Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ueman committed Sep 13, 2024
1 parent 44cfd51 commit ef0931b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
56 changes: 56 additions & 0 deletions passkit/lib/src/write_signature.dart
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,
);
}
4 changes: 3 additions & 1 deletion passkit/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ dependencies:
intl: ^0.19.0
json_annotation: ^4.9.0
meta: ^1.0.0
pkcs7: ^1.0.3
pem: ^2.0.0
pkcs7: ^1.0.0
pointycastle: ^3.9.0

dev_dependencies:
build_runner: ^2.3.2
Expand Down

0 comments on commit ef0931b

Please sign in to comment.