use of sun.security.krb5.Asn1Exception in project jmulticard by ctt-gob-es.
the class Sequence method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
final Tlv mainTlv = new Tlv(getRawDerValue());
checkTag(mainTlv.getTag());
int offset = 0;
Tlv tlv;
byte[] remainingBytes;
DecoderObject tmpDo;
final byte[] rawValue = mainTlv.getValue();
for (int i = 0; i < this.elementsTypes.length; i++) {
remainingBytes = new byte[rawValue.length - offset];
System.arraycopy(rawValue, offset, remainingBytes, 0, remainingBytes.length);
try {
tlv = new Tlv(remainingBytes);
tmpDo = this.elementsTypes[i].getElementType().getConstructor().newInstance();
tmpDo.checkTag(tlv.getTag());
tmpDo.setDerValue(tlv.getBytes());
} catch (final Exception e) {
if (this.elementsTypes[i].isOptional()) {
// Como no ha avanzado el offset, se reutilizara el tipo en el proximo elemento
continue;
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new Asn1Exception("Error en el elemento " + i + " (" + this.elementsTypes[i].getElementType().getName() + ") de la secuencia ASN.1: " + e, e);
}
// El offset se avanza antes del continue de la opcionalidad
offset = offset + tlv.getBytes().length;
this.elements.add(tmpDo);
}
}
use of sun.security.krb5.Asn1Exception in project jmulticard by ctt-gob-es.
the class SequenceOf method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
Tlv tlv = new Tlv(getRawDerValue());
checkTag(tlv.getTag());
int offset = 0;
byte[] remainingBytes;
DecoderObject tmpDo;
final byte[] valueBytes = tlv.getValue();
this.sequenceObjects = new Vector<>();
while (offset < valueBytes.length) {
remainingBytes = new byte[valueBytes.length - offset];
System.arraycopy(valueBytes, offset, remainingBytes, 0, remainingBytes.length);
tlv = new Tlv(remainingBytes);
try {
tmpDo = this.elementsType.getConstructor().newInstance();
} catch (final Exception e) {
throw new Asn1Exception(// $NON-NLS-1$
"No se ha podido instanciar un " + this.elementsType.getName() + " en la secuencia: " + // $NON-NLS-1$
e, // $NON-NLS-1$
e);
}
offset = offset + tlv.getBytes().length;
tmpDo.checkTag(tlv.getTag());
tmpDo.setDerValue(tlv.getBytes());
this.sequenceObjects.add(tmpDo);
}
}
use of sun.security.krb5.Asn1Exception in project jmulticard by ctt-gob-es.
the class ContextSpecific method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
final Tlv tlv = new Tlv(this.getRawDerValue());
final DecoderObject tmpDo;
try {
tmpDo = this.elementType.getConstructor().newInstance();
} catch (final Exception e) {
throw new Asn1Exception(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido instanciar un " + this.elementType.getName() + " en el contexto especifico: " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
tmpDo.setDerValue(tlv.getValue());
this.object = tmpDo;
}
use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.
the class EncKrbPrivPart method init.
/**
* Initializes an EncKrbPrivPart 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.
*/
private void init(DerValue encoding) throws Asn1Exception, IOException {
DerValue der, subDer;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1C) || (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() & (byte) 0x1F) == (byte) 0x00) {
userData = subDer.getData().getOctetString();
} else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
timestamp = KerberosTime.parse(der.getData(), (byte) 0x01, true);
if ((der.getData().peekByte() & 0x1F) == 0x02) {
subDer = der.getData().getDerValue();
usec = new Integer(subDer.getData().getBigInteger().intValue());
} else {
usec = null;
}
if ((der.getData().peekByte() & 0x1F) == 0x03) {
subDer = der.getData().getDerValue();
seqNumber = new Integer(subDer.getData().getBigInteger().intValue());
} else {
seqNumber = null;
}
sAddress = HostAddress.parse(der.getData(), (byte) 0x04, false);
if (der.getData().available() > 0) {
rAddress = HostAddress.parse(der.getData(), (byte) 0x05, true);
}
if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
}
use of sun.security.krb5.Asn1Exception in project jdk8u_jdk by JetBrains.
the class EncKrbCredPart method init.
/**
* Initializes an EncKrbCredPart 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.
*/
private void init(DerValue encoding) throws Asn1Exception, IOException, RealmException {
DerValue der, subDer;
//may not be the correct error code for a tag
//mismatch on an encrypted structure
nonce = null;
timeStamp = null;
usec = null;
sAddress = null;
rAddress = null;
if (((encoding.getTag() & (byte) 0x1F) != (byte) 0x1D) || (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() & (byte) 0x1F) == (byte) 0x00) {
DerValue[] derValues = subDer.getData().getSequence(1);
ticketInfo = new KrbCredInfo[derValues.length];
for (int i = 0; i < derValues.length; i++) {
ticketInfo[i] = new KrbCredInfo(derValues[i]);
}
} else {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
if (der.getData().available() > 0) {
if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x01) {
subDer = der.getData().getDerValue();
nonce = new Integer(subDer.getData().getBigInteger().intValue());
}
}
if (der.getData().available() > 0) {
timeStamp = KerberosTime.parse(der.getData(), (byte) 0x02, true);
}
if (der.getData().available() > 0) {
if (((byte) (der.getData().peekByte()) & (byte) 0x1F) == (byte) 0x03) {
subDer = der.getData().getDerValue();
usec = new Integer(subDer.getData().getBigInteger().intValue());
}
}
if (der.getData().available() > 0) {
sAddress = HostAddress.parse(der.getData(), (byte) 0x04, true);
}
if (der.getData().available() > 0) {
rAddress = HostAddresses.parse(der.getData(), (byte) 0x05, true);
}
if (der.getData().available() > 0) {
throw new Asn1Exception(Krb5.ASN1_BAD_ID);
}
}
Aggregations