use of com.mindbright.security.pkcs12.SafeContents in project SpringRemote by HaleyWang.
the class PKCS12KeyStore method processSafeContents.
private void processSafeContents(byte[] scBer) throws IOException {
ByteArrayInputStream ba = new ByteArrayInputStream(scBer);
SafeContents sc = new SafeContents();
ASN1DER ber = new ASN1DER();
ber.decode(ba, sc);
for (int j = 0; j < sc.getCount(); j++) {
SafeBag safeBag = sc.getSafeBag(j);
String friendlyName = getAttribute(safeBag, "1.2.840.113549.1.9.20");
String localKeyId = getAttribute(safeBag, "1.2.840.113549.1.9.21");
if (friendlyName != null) {
if (localKeyId != null) {
name2id.put(friendlyName, localKeyId);
}
if (!aliases.contains(friendlyName)) {
aliases.addElement(friendlyName);
}
} else if (localKeyId != null) {
name2id.put(localKeyId, localKeyId);
if (!aliases.contains(localKeyId)) {
aliases.addElement(localKeyId);
}
}
switch(safeBag.getBagType()) {
case SafeBag.TYPE_PKCS8_SHROUDED_KEYBAG:
EncryptedPrivateKeyInfo keyBag = (EncryptedPrivateKeyInfo) safeBag.bagValue.getValue();
privateKeys.put(localKeyId, keyBag);
break;
case SafeBag.TYPE_CERTBAG:
CertBag cb = (CertBag) safeBag.bagValue.getValue();
byte[] derCert = ((ASN1OctetString) cb.certValue.getValue()).getRaw();
if (localKeyId == null) {
/*
* Trusted certs don't have a localKeyId
*/
localKeyId = friendlyName;
} else {
certificates.put(localKeyId, derCert);
}
break;
default:
throw new IOException("SafeBag type not supported: " + safeBag.bagId.getString());
}
}
}
Aggregations