Skip to content

Commit bb52a06

Browse files
committed
Align doCancel pattern in 'P11Cipher::implDoFinal(byte[]..' to 'P11Cipher::implDoFinal(ByteBuffer..'. Better documentation in P11Cipher. Copyright date updated.
1 parent 65dcc0d commit bb52a06

File tree

1 file changed

+32
-4
lines changed
  • src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11

1 file changed

+32
-4
lines changed

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -635,6 +635,10 @@ private int implUpdate(byte[] in, int inOfs, int inLen,
635635
throw (ShortBufferException)
636636
(new ShortBufferException().initCause(e));
637637
}
638+
// Some implementations such as the NSS Software Token do not
639+
// cancel the operation upon a C_EncryptUpdate/C_DecryptUpdate
640+
// failure (as required by the PKCS#11 standard). See JDK-8258833
641+
// for further information.
638642
reset(true);
639643
throw new ProviderException("update() failed", e);
640644
}
@@ -753,6 +757,10 @@ private int implUpdate(ByteBuffer inBuffer, ByteBuffer outBuffer)
753757
throw (ShortBufferException)
754758
(new ShortBufferException().initCause(e));
755759
}
760+
// Some implementations such as the NSS Software Token do not
761+
// cancel the operation upon a C_EncryptUpdate/C_DecryptUpdate
762+
// failure (as required by the PKCS#11 standard). See JDK-8258833
763+
// for further information.
756764
reset(true);
757765
throw new ProviderException("update() failed", e);
758766
}
@@ -777,9 +785,14 @@ private int implDoFinal(byte[] out, int outOfs, int outLen)
777785
0, padBuffer, 0, actualPadLen,
778786
0, out, outOfs, outLen);
779787
}
788+
// Some implementations such as the NSS Software Token do not
789+
// cancel the operation upon a C_EncryptUpdate failure (as
790+
// required by the PKCS#11 standard). Cancel is not needed
791+
// only after this point. See JDK-8258833 for further
792+
// information.
793+
doCancel = false;
780794
k += token.p11.C_EncryptFinal(session.id(),
781795
0, out, (outOfs + k), (outLen - k));
782-
doCancel = false;
783796
} else {
784797
// Special handling to match SunJCE provider behavior
785798
if (bytesBuffered == 0 && padBufferLen == 0) {
@@ -791,17 +804,22 @@ private int implDoFinal(byte[] out, int outOfs, int outLen)
791804
padBuffer, 0, padBufferLen, 0, padBuffer, 0,
792805
padBuffer.length);
793806
}
807+
// Some implementations such as the NSS Software Token do not
808+
// cancel the operation upon a C_DecryptUpdate failure (as
809+
// required by the PKCS#11 standard). Cancel is not needed
810+
// only after this point. See JDK-8258833 for further
811+
// information.
812+
doCancel = false;
794813
k += token.p11.C_DecryptFinal(session.id(), 0, padBuffer, k,
795814
padBuffer.length - k);
796-
doCancel = false;
797815

798816
int actualPadLen = paddingObj.unpad(padBuffer, k);
799817
k -= actualPadLen;
800818
System.arraycopy(padBuffer, 0, out, outOfs, k);
801819
} else {
820+
doCancel = false;
802821
k = token.p11.C_DecryptFinal(session.id(), 0, out, outOfs,
803822
outLen);
804-
doCancel = false;
805823
}
806824
}
807825
return k;
@@ -851,6 +869,11 @@ private int implDoFinal(ByteBuffer outBuffer)
851869
0, padBuffer, 0, actualPadLen,
852870
outAddr, outArray, outOfs, outLen);
853871
}
872+
// Some implementations such as the NSS Software Token do not
873+
// cancel the operation upon a C_EncryptUpdate failure (as
874+
// required by the PKCS#11 standard). Cancel is not needed
875+
// only after this point. See JDK-8258833 for further
876+
// information.
854877
doCancel = false;
855878
k += token.p11.C_EncryptFinal(session.id(),
856879
outAddr, outArray, (outOfs + k), (outLen - k));
@@ -867,6 +890,11 @@ private int implDoFinal(ByteBuffer outBuffer)
867890
0, padBuffer, 0, padBuffer.length);
868891
padBufferLen = 0;
869892
}
893+
// Some implementations such as the NSS Software Token do not
894+
// cancel the operation upon a C_DecryptUpdate failure (as
895+
// required by the PKCS#11 standard). Cancel is not needed
896+
// only after this point. See JDK-8258833 for further
897+
// information.
870898
doCancel = false;
871899
k += token.p11.C_DecryptFinal(session.id(),
872900
0, padBuffer, k, padBuffer.length - k);

0 commit comments

Comments
 (0)