-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add function to return a Certificate
from DER format
#293
Conversation
if worked, can add load_cert function
Hi @jiangshaoqi, thanks for the contribution. Can you speak more to your motivation for wanting this? You can already construct |
Hello @cpu , thank you for the reply. In Also, In my case, if i sign it again to get the Certificate, there will be some difference between my original certificate, because of x509 parser. for example, in my certificate: I also see people asking for: [https://github.com//issues/274] What i did work for me, and i think it might be good for others. From your reply, i think i should also try use rcgen generate a CA certificate DER, get its If it is same, please ignore my request |
I just checked: use rcgen generate a CA certificate DER, get its It also works in my scenario, please ignore my request and have a good day! |
@jiangshaoqi I would be curious how you achieved the same certificate because I can't seem to reproduce it myself. When I run the following code and the assertion fails: let CertifiedKey { cert, key_pair } = generate_simple_self_signed(vec!["abc".into()]).unwrap();
let before = cert.pem();
println!("{:?}", cert.pem());
println!("{:?}\n\n\n", key_pair.serialize_pem());
let key_pair = rcgen::KeyPair::from_pem(&key_pair.serialize_pem()).unwrap();
let cert = CertificateParams::from_ca_cert_der(&cert.try_into().unwrap())
.unwrap()
.self_signed(&key_pair)
.unwrap();
println!("{:?}", cert.pem());
println!("{:?}\n\n\n", key_pair.serialize_pem());
assert_eq!(before, cert.pem()); I kinda feel like this PR should be reopened and merged as a stop gap solution. |
@oscartbeaumont I found use let key_pair = KeyPair::generate_for(&PKCS_ED25519).unwrap();
let cert_params = CertificateParams::new(vec!["abc".into()]).unwrap();
let cert = cert_params.self_signed(&key_pair).unwrap();
let before = cert.pem();
println!("{:?}", cert.pem());
println!("{:?}\n\n\n", key_pair.serialize_pem());
let key_pair = rcgen::KeyPair::from_pem(&key_pair.serialize_pem()).unwrap();
let cert = CertificateParams::from_ca_cert_der(&cert.try_into().unwrap())
.unwrap()
.self_signed(&key_pair)
.unwrap();
println!("{:?}", cert.pem());
println!("{:?}\n\n\n", key_pair.serialize_pem());
assert_eq!(before, cert.pem()); The problem is that the digital signatures are different between these two certificates. I've found in the source code (sign signature) that the kind algorithm member within However, Testing shows that I'm wondering if it's possible to use:
|
Why is this a problem?
Browsers don't support ED25519 certificates, unfortunately. |
My scenario involves generating a root CA certificate, storing it in a file or database (and Adding to the operating system's trusted root store), and later restoring it to issue leaf certificates. For me, the problem is the fingerprint of a restored root CA certificate does not match the original.
Thanks for the clarification. Now I understand why browser still show certificate warning. |
It's still not obvious to me why that is a problem. Here's some example code that worked for me: https://gist.github.com/djc/04d8d91fd5fe4ee6b7026373c5f247f4 (Not quite in a web context, but probably close enough.) If you still believe there is a use case that rcgen doesn't cover, I suggest you open a new issue with a clear explanation of your use case rather than commenting on this confusingly-named closed PR. |
I understand. Thank you very much for your assistance. |
@oscartbeaumont For me it works only after the generating the cert with rustls. If it would work for you:
|
add "from_der" function in the Certificate implementation. This function can create a Certificate struct from DER encoded certificate.
Make sure the certificate match the format of x509-parser in rcgen, or the generated
Certificate
will be different.A safe way of this usage is to load the DER certificate generated by rcgen itself.