ios-csr icon indicating copy to clipboard operation
ios-csr copied to clipboard

signature not valid

Open zealit opened this issue 5 years ago • 3 comments

the CSR created by this code gives some error. When I verify the CSR (online) I get the messages:

  • signature not valid
  • Certificate Signing Request (CSR) Is Missing a NULL Value

this is my code:

//create private key NSData* tag = [@"name" dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary* attributes = @{ (id)kSecAttrKeyType: (id)kSecAttrKeyTypeRSA, (id)kSecAttrKeySizeInBits: @2048, (id)kSecPrivateKeyAttrs: @{ (id)kSecAttrIsPermanent: @YES, (id)kSecAttrApplicationTag: tag, }, };

CFErrorRef error = NULL;
SecKeyRef privateKey = SecKeyCreateRandomKey((__bridge CFDictionaryRef)attributes,&error);
if (!privateKey) {
    NSError *err = CFBridgingRelease(error);  // ARC takes ownership
    // Handle the error. . .
}

//create public key
SecKeyRef publicKey = SecKeyCopyPublicKey(privateKey);
NSData *pubKey = (NSData *)CFBridgingRelease(SecKeyCopyExternalRepresentation(publicKey, &error));

CertificateSigningRequest *sccsr = [[CertificateSigningRequest alloc] init];
sccsr.commonName = @"CommonName";

NSData *certificateRequest = [sccsr build:pubKey privateKey:privateKey];
NSString *s = [certificateRequest base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

NSString *strCertificateRequest = @"-----BEGIN CERTIFICATE REQUEST-----\n";
strCertificateRequest = [strCertificateRequest stringByAppendingString:s];
strCertificateRequest = [strCertificateRequest stringByAppendingString:@"\n-----END CERTIFICATE REQUEST-----\n"];
NSLog(@"%@" , strCertificateRequest);

return strCertificateRequest;

zealit avatar Aug 15 '19 09:08 zealit

@zealit you can use this library, it works on both RSA and EC https://github.com/aleemrazzaq/iOSCSR

aleemrazzaq avatar Aug 19 '19 08:08 aleemrazzaq

this is also for iOS, not for OS X unfortunately. Is it possible to adapt your library so it's useful on OS X?

zealit avatar Aug 20 '19 13:08 zealit

Any updates on this one? facing the same issue

matej-podzemny avatar Jun 12 '24 09:06 matej-podzemny