public static Pfx getInstance( Object obj) { if (obj instanceof Pfx) { return (Pfx)obj; } if (obj != null) { return new Pfx(ASN1Sequence.getInstance(obj)); } return null; }
/** * Just re-encode the outer layer of the PKCS#12 file to definite length encoding. * * @param berPKCS12File - original PKCS#12 file * @return a byte array representing the DER encoding of the PFX structure * @throws IOException */ public static byte[] convertToDefiniteLength(byte[] berPKCS12File) throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); Pfx pfx = Pfx.getInstance(berPKCS12File); bOut.reset(); dOut.writeObject(pfx); return bOut.toByteArray(); }
/** * Return whether or not there is MAC attached to this file. * * @return true if there is, false otherwise. */ public boolean hasMac() { return pfx.getMacData() != null; }
throws IOException Pfx pfx = Pfx.getInstance(berPKCS12File); ContentInfo info = pfx.getAuthSafe(); MacData mData = pfx.getMacData(); try pfx = new Pfx(info, mData);
Pfx bag = Pfx.getInstance(obj); ContentInfo info = bag.getAuthSafe(); Vector chain = new Vector(); boolean unmarkedKey = false; boolean wrongPKCS12Zero = false; if (bag.getMacData() != null) // check the mac code MacData mData = bag.getMacData(); DigestInfo dInfo = mData.getMac(); AlgorithmIdentifier algId = dInfo.getAlgorithmId();
/** * Verify the MacData attached to the PFX is consistent with what is expected. * * @param macCalcProviderBuilder provider builder for the calculator for the MAC * @param password password to use * @return true if mac data is valid, false otherwise. * @throws PKCSException if there is a problem evaluating the MAC. * @throws IllegalStateException if no MAC is actually present */ public boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder, char[] password) throws PKCSException { if (hasMac()) { MacData pfxmData = pfx.getMacData(); MacDataGenerator mdGen = new MacDataGenerator(macCalcProviderBuilder.get(new AlgorithmIdentifier(pfxmData.getMac().getAlgorithmId().getAlgorithm(), new PKCS12PBEParams(pfxmData.getSalt(), pfxmData.getIterationCount().intValue())))); try { MacData mData = mdGen.build( password, ASN1OctetString.getInstance(pfx.getAuthSafe().getContent()).getOctets()); return Arrays.constantTimeAreEqual(mData.getEncoded(), pfx.getMacData().getEncoded()); } catch (IOException e) { throw new PKCSException("unable to process AuthSafe: " + e.getMessage()); } } throw new IllegalStateException("no MAC present on PFX"); }
/** * Return the content infos in the AuthenticatedSafe contained in this Pfx. * * @return an array of ContentInfo. */ public ContentInfo[] getContentInfos() { ASN1Sequence seq = ASN1Sequence.getInstance(ASN1OctetString.getInstance(this.pfx.getAuthSafe().getContent()).getOctets()); ContentInfo[] content = new ContentInfo[seq.size()]; for (int i = 0; i != seq.size(); i++) { content[i] = ContentInfo.getInstance(seq.getObjectAt(i)); } return content; }
public byte[] getEncoded() throws IOException { return toASN1Structure().getEncoded(); }
throws IOException Pfx pfx = Pfx.getInstance(berPKCS12File); ContentInfo info = pfx.getAuthSafe(); MacData mData = pfx.getMacData(); try pfx = new Pfx(info, mData);
Pfx bag = Pfx.getInstance(obj); ContentInfo info = bag.getAuthSafe(); Vector chain = new Vector(); boolean unmarkedKey = false; boolean wrongPKCS12Zero = false; if (bag.getMacData() != null) // check the mac code MacData mData = bag.getMacData(); DigestInfo dInfo = mData.getMac(); macAlgorithm = dInfo.getAlgorithmId();
/** * Verify the MacData attached to the PFX is consistent with what is expected. * * @param macCalcProviderBuilder provider builder for the calculator for the MAC * @param password password to use * @return true if mac data is valid, false otherwise. * @throws PKCSException if there is a problem evaluating the MAC. * @throws IllegalStateException if no MAC is actually present */ public boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder, char[] password) throws PKCSException { if (hasMac()) { MacData pfxmData = pfx.getMacData(); MacDataGenerator mdGen = new MacDataGenerator(macCalcProviderBuilder.get(new AlgorithmIdentifier(pfxmData.getMac().getAlgorithmId().getAlgorithm(), new PKCS12PBEParams(pfxmData.getSalt(), pfxmData.getIterationCount().intValue())))); try { MacData mData = mdGen.build( password, ASN1OctetString.getInstance(pfx.getAuthSafe().getContent()).getOctets()); return Arrays.constantTimeAreEqual(mData.getEncoded(), pfx.getMacData().getEncoded()); } catch (IOException e) { throw new PKCSException("unable to process AuthSafe: " + e.getMessage()); } } throw new IllegalStateException("no MAC present on PFX"); }
/** * Return the content infos in the AuthenticatedSafe contained in this Pfx. * * @return an array of ContentInfo. */ public ContentInfo[] getContentInfos() { ASN1Sequence seq = ASN1Sequence.getInstance(ASN1OctetString.getInstance(this.pfx.getAuthSafe().getContent()).getOctets()); ContentInfo[] content = new ContentInfo[seq.size()]; for (int i = 0; i != seq.size(); i++) { content[i] = ContentInfo.getInstance(seq.getObjectAt(i)); } return content; }
public byte[] getEncoded() throws IOException { return toASN1Structure().getEncoded(); }
public static Pfx getInstance( Object obj) { if (obj instanceof Pfx) { return (Pfx)obj; } if (obj != null) { return new Pfx(ASN1Sequence.getInstance(obj)); } return null; }
/** * Return whether or not there is MAC attached to this file. * * @return true if there is, false otherwise. */ public boolean hasMac() { return pfx.getMacData() != null; }
/** * Just re-encode the outer layer of the PKCS#12 file to definite length encoding. * * @param berPKCS12File - original PKCS#12 file * @return a byte array representing the DER encoding of the PFX structure * @throws IOException */ public static byte[] convertToDefiniteLength(byte[] berPKCS12File) throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); DEROutputStream dOut = new DEROutputStream(bOut); Pfx pfx = Pfx.getInstance(berPKCS12File); bOut.reset(); dOut.writeObject(pfx); return bOut.toByteArray(); }
/** * Return a Pfx with the outer wrapper encoded as asked for. For example, Pfx is a usually * a BER encoded object, to get one with DefiniteLength encoding use: * <pre> * getEncoded(ASN1Encoding.DL) * </pre> * @param encoding encoding style (ASN1Encoding.DER, ASN1Encoding.DL, ASN1Encoding.BER) * @return a byte array containing the encoded object. * @throws IOException */ public byte[] getEncoded(String encoding) throws IOException { return toASN1Structure().getEncoded(encoding); } }
Pfx pfx = new Pfx(mainInfo, mData);
/** * Return the algorithm identifier describing the MAC algorithm * * @return the AlgorithmIdentifier representing the MAC algorithm, null if none present. */ public AlgorithmIdentifier getMacAlgorithmID() { MacData md = pfx.getMacData(); if (md != null) { return md.getMac().getAlgorithmId(); } return null; }
private static Pfx parseBytes(byte[] pfxEncoding) throws IOException { try { return Pfx.getInstance(ASN1Primitive.fromByteArray(pfxEncoding)); } catch (ClassCastException e) { throw new CertIOException("malformed data: " + e.getMessage(), e); } catch (IllegalArgumentException e) { throw new CertIOException("malformed data: " + e.getMessage(), e); } }