-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:passkit/src/apple_wwdr_certificate.dart'; | ||
import 'package:pem/pem.dart'; | ||
import 'package:pkcs7/pkcs7.dart'; | ||
import 'package:pointycastle/pointycastle.dart'; | ||
|
||
Uint8List writeSignature( | ||
String userCertificate, | ||
Uint8List manifestBytes, | ||
) { | ||
final privateKey = _createPrivateKey(userCertificate); | ||
final issuer = X509.fromPem(userCertificate); | ||
|
||
final pkcs7Builder = Pkcs7Builder(); | ||
// Add one or more certificates | ||
pkcs7Builder.addCertificate(wwdrG4); | ||
|
||
// Create a signature information object | ||
final signerInfo = | ||
Pkcs7SignerInfoBuilder.rsa(issuer: issuer, privateKey: privateKey); | ||
|
||
// Add the digest to sign | ||
signerInfo.addSMimeDigest(digest: manifestBytes, signingTime: DateTime.now()); | ||
|
||
// Add the signature information | ||
pkcs7Builder.addSignerInfo(signerInfo); | ||
|
||
// Add a certificate revocation list | ||
pkcs7Builder.addCRL( | ||
CertificateRevocationList.fromDer( | ||
Uint8List.fromList(worldwide_Developer_Relations_G4), | ||
), | ||
); | ||
|
||
final pkcs7 = pkcs7Builder.build(); | ||
return pkcs7.der; | ||
} | ||
|
||
RSAPrivateKey _createPrivateKey(String certificate) { | ||
final pem = decodePemBlocks(PemLabel.privateKey, certificate); | ||
|
||
final modulus = | ||
ASN1Object.fromBytes(Uint8List.fromList(pem[1])) as ASN1Integer; | ||
final exponent = | ||
ASN1Object.fromBytes(Uint8List.fromList(pem[3])) as ASN1Integer; | ||
final p = ASN1Object.fromBytes(Uint8List.fromList(pem[4])) as ASN1Integer; | ||
final q = ASN1Object.fromBytes(Uint8List.fromList(pem[5])) as ASN1Integer; | ||
|
||
return RSAPrivateKey( | ||
modulus.integer!, | ||
exponent.integer!, | ||
p.integer, | ||
q.integer, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters