use of codec.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.
the class KerberosTime method parse.
/**
* Parse (unmarshal) a kerberostime from a DER input stream. This form
* parsing might be used when expanding a value which is part of
* a constructed sequence and uses explicitly tagged type.
*
* @exception Asn1Exception on error.
* @param data the Der input stream value, which contains
* one or more marshaled value.
* @param explicitTag tag number.
* @param optional indicates if this data field is optional
* @return an instance of KerberosTime.
*
*/
public static KerberosTime parse(DerInputStream data, byte explicitTag, boolean optional) throws Asn1Exception, IOException {
if ((optional) && (((byte) data.peekByte() & (byte) 0x1F) != explicitTag))
return null;
DerValue der = data.getDerValue();
if (explicitTag != (der.getTag() & (byte) 0x1F)) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
} else {
DerValue subDer = der.getData().getDerValue();
Date temp = subDer.getGeneralizedTime();
return new KerberosTime(temp.getTime(), 0);
}
}
use of codec.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.
the class KRBPriv method init.
/**
* Initializes an KRBPriv object.
* @param encoding a single DER-encoded value.
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
* @exception IOException if an I/O error occurs while reading encoded data.
* @exception KrbApErrException if the value read from the DER-encoded data
* stream does not match the pre-defined value.
*/
private void init(DerValue encoding) throws Asn1Exception, KrbApErrException, IOException {
DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x15) || (encoding.isApplication() != true) || (encoding.isConstructed() != true))
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence)
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x00) {
pvno = subDer.getData().getBigInteger().intValue();
if (pvno != Krb5.PVNO) {
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
}
} else
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x01) {
msgType = subDer.getData().getBigInteger().intValue();
if (msgType != Krb5.KRB_PRIV)
throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
} else
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
encPart = EncryptedData.parse(der.getData(), (byte) 0x03, false);
if (der.getData().available() > 0)
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
use of codec.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.
the class KRBSafe method init.
/**
* Initializes an KRBSafe object.
* @param encoding a single DER-encoded value.
* @exception Asn1Exception if an error occurs while decoding an ASN1 encoded data.
* @exception IOException if an I/O error occurs while reading encoded data.
* @exception RealmException if an error occurs while parsing a Realm object.
* @exception KrbApErrException if the value read from the DER-encoded data
* stream does not match the pre-defined value.
*/
private void init(DerValue encoding) throws Asn1Exception, RealmException, KrbApErrException, IOException {
DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x14) || (encoding.isApplication() != true) || (encoding.isConstructed() != true))
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
der = encoding.getData().getDerValue();
if (der.getTag() != DerValue.tag_Sequence)
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x00) {
pvno = subDer.getData().getBigInteger().intValue();
if (pvno != Krb5.PVNO)
throw new KrbApErrException(Krb5.KRB_AP_ERR_BADVERSION);
} else
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
subDer = der.getData().getDerValue();
if ((subDer.getTag() & 0x1F) == 0x01) {
msgType = subDer.getData().getBigInteger().intValue();
if (msgType != Krb5.KRB_SAFE)
throw new KrbApErrException(Krb5.KRB_AP_ERR_MSG_TYPE);
} else
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
safeBody = KRBSafeBody.parse(der.getData(), (byte) 0x02, false);
cksum = Checksum.parse(der.getData(), (byte) 0x03, false);
if (der.getData().available() > 0)
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
use of codec.asn1.ASN1Exception in project jdk8u_jdk by JetBrains.
the class KeyImpl method readObject.
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
try {
EncryptionKey encKey = new EncryptionKey(new DerValue((byte[]) ois.readObject()));
keyType = encKey.getEType();
keyBytes = encKey.getBytes();
} catch (Asn1Exception ae) {
throw new IOException(ae.getMessage());
}
}
use of codec.asn1.ASN1Exception in project core by jcryptool.
the class ImportExportManager method exportKeyPair.
public void exportKeyPair(IPath path, PrivateKey key, Certificate[] chain, char[] password) {
PFX pfx;
X509Certificate[] x509Chain = convert(chain);
try {
if (x509Chain.length > 1) {
X509Certificate[] shortChain = new X509Certificate[x509Chain.length - 1];
for (int i = 1; i < chain.length; i++) {
shortChain[i - 1] = x509Chain[i];
}
pfx = new PFX(key, x509Chain[0], shortChain, password, null, null);
} else {
pfx = new PFX(key, x509Chain[0], null, password, null, null);
}
IFileStore fileStore = EFS.getStore(URIUtil.toURI(path));
OutputStream os = new BufferedOutputStream(fileStore.openOutputStream(EFS.APPEND, null));
DEREncoder encoder = new DEREncoder(os);
pfx.encode(encoder);
encoder.close();
os.close();
} catch (CertificateEncodingException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "CertificateEncodingException while creating a PFX", e, true);
} catch (GeneralSecurityException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "GeneralSecurityException while creating a PFX", e, true);
} catch (ASN1Exception e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "ASN1Exception while creating a PFX", e, true);
} catch (IOException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "IOException while creating a PFX", e, true);
} catch (CoreException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, "CoreException while creating a PFX", e, true);
}
}
Aggregations