src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Signature.java
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 49700 490292739652
child 50364 00ebc17f3cc6
equal deleted inserted replaced
56541:92cbbfc996f3 56542:56aaa6cb3693
    29 import java.math.BigInteger;
    29 import java.math.BigInteger;
    30 import java.nio.ByteBuffer;
    30 import java.nio.ByteBuffer;
    31 
    31 
    32 import java.security.*;
    32 import java.security.*;
    33 import java.security.interfaces.*;
    33 import java.security.interfaces.*;
       
    34 import java.security.spec.AlgorithmParameterSpec;
    34 import sun.nio.ch.DirectBuffer;
    35 import sun.nio.ch.DirectBuffer;
    35 
    36 
    36 import sun.security.util.*;
    37 import sun.security.util.*;
    37 import sun.security.x509.AlgorithmId;
    38 import sun.security.x509.AlgorithmId;
    38 
    39 
   432                 ("Key is too short for this signature algorithm");
   433                 ("Key is too short for this signature algorithm");
   433         }
   434         }
   434     }
   435     }
   435 
   436 
   436     // see JCA spec
   437     // see JCA spec
       
   438     @Override
   437     protected void engineInitVerify(PublicKey publicKey)
   439     protected void engineInitVerify(PublicKey publicKey)
   438             throws InvalidKeyException {
   440             throws InvalidKeyException {
   439         if (publicKey == null) {
   441         if (publicKey == null) {
   440             throw new InvalidKeyException("Key must not be null");
   442             throw new InvalidKeyException("Key must not be null");
   441         }
   443         }
   448         p11Key = P11KeyFactory.convertKey(token, publicKey, keyAlgorithm);
   450         p11Key = P11KeyFactory.convertKey(token, publicKey, keyAlgorithm);
   449         initialize();
   451         initialize();
   450     }
   452     }
   451 
   453 
   452     // see JCA spec
   454     // see JCA spec
       
   455     @Override
   453     protected void engineInitSign(PrivateKey privateKey)
   456     protected void engineInitSign(PrivateKey privateKey)
   454             throws InvalidKeyException {
   457             throws InvalidKeyException {
   455         if (privateKey == null) {
   458         if (privateKey == null) {
   456             throw new InvalidKeyException("Key must not be null");
   459             throw new InvalidKeyException("Key must not be null");
   457         }
   460         }
   464         p11Key = P11KeyFactory.convertKey(token, privateKey, keyAlgorithm);
   467         p11Key = P11KeyFactory.convertKey(token, privateKey, keyAlgorithm);
   465         initialize();
   468         initialize();
   466     }
   469     }
   467 
   470 
   468     // see JCA spec
   471     // see JCA spec
       
   472     @Override
   469     protected void engineUpdate(byte b) throws SignatureException {
   473     protected void engineUpdate(byte b) throws SignatureException {
   470         ensureInitialized();
   474         ensureInitialized();
   471         switch (type) {
   475         switch (type) {
   472         case T_UPDATE:
   476         case T_UPDATE:
   473             buffer[0] = b;
   477             buffer[0] = b;
   488             throw new ProviderException("Internal error");
   492             throw new ProviderException("Internal error");
   489         }
   493         }
   490     }
   494     }
   491 
   495 
   492     // see JCA spec
   496     // see JCA spec
       
   497     @Override
   493     protected void engineUpdate(byte[] b, int ofs, int len)
   498     protected void engineUpdate(byte[] b, int ofs, int len)
   494             throws SignatureException {
   499             throws SignatureException {
   495         ensureInitialized();
   500         ensureInitialized();
   496         if (len == 0) {
   501         if (len == 0) {
   497             return;
   502             return;
   525             throw new ProviderException("Internal error");
   530             throw new ProviderException("Internal error");
   526         }
   531         }
   527     }
   532     }
   528 
   533 
   529     // see JCA spec
   534     // see JCA spec
       
   535     @Override
   530     protected void engineUpdate(ByteBuffer byteBuffer) {
   536     protected void engineUpdate(ByteBuffer byteBuffer) {
   531         ensureInitialized();
   537         ensureInitialized();
   532         int len = byteBuffer.remaining();
   538         int len = byteBuffer.remaining();
   533         if (len <= 0) {
   539         if (len <= 0) {
   534             return;
   540             return;
   572             throw new ProviderException("Internal error");
   578             throw new ProviderException("Internal error");
   573         }
   579         }
   574     }
   580     }
   575 
   581 
   576     // see JCA spec
   582     // see JCA spec
       
   583     @Override
   577     protected byte[] engineSign() throws SignatureException {
   584     protected byte[] engineSign() throws SignatureException {
   578         ensureInitialized();
   585         ensureInitialized();
   579         try {
   586         try {
   580             byte[] signature;
   587             byte[] signature;
   581             if (type == T_UPDATE) {
   588             if (type == T_UPDATE) {
   631             session = token.releaseSession(session);
   638             session = token.releaseSession(session);
   632         }
   639         }
   633     }
   640     }
   634 
   641 
   635     // see JCA spec
   642     // see JCA spec
       
   643     @Override
   636     protected boolean engineVerify(byte[] signature) throws SignatureException {
   644     protected boolean engineVerify(byte[] signature) throws SignatureException {
   637         ensureInitialized();
   645         ensureInitialized();
   638         try {
   646         try {
   639             if (!p1363Format) {
   647             if (!p1363Format) {
   640                 if (keyAlgorithm.equals("DSA")) {
   648                 if (keyAlgorithm.equals("DSA")) {
   822         return t;
   830         return t;
   823     }
   831     }
   824 
   832 
   825     // see JCA spec
   833     // see JCA spec
   826     @SuppressWarnings("deprecation")
   834     @SuppressWarnings("deprecation")
       
   835     @Override
   827     protected void engineSetParameter(String param, Object value)
   836     protected void engineSetParameter(String param, Object value)
   828             throws InvalidParameterException {
   837             throws InvalidParameterException {
   829         throw new UnsupportedOperationException("setParameter() not supported");
   838         throw new UnsupportedOperationException("setParameter() not supported");
   830     }
   839     }
   831 
   840 
   832     // see JCA spec
   841     // see JCA spec
       
   842     @Override
       
   843     protected void engineSetParameter(AlgorithmParameterSpec params)
       
   844             throws InvalidAlgorithmParameterException {
       
   845         if (params != null) {
       
   846             throw new InvalidAlgorithmParameterException("No parameter accepted");
       
   847         }
       
   848     }
       
   849 
       
   850     // see JCA spec
   833     @SuppressWarnings("deprecation")
   851     @SuppressWarnings("deprecation")
       
   852     @Override
   834     protected Object engineGetParameter(String param)
   853     protected Object engineGetParameter(String param)
   835             throws InvalidParameterException {
   854             throws InvalidParameterException {
   836         throw new UnsupportedOperationException("getParameter() not supported");
   855         throw new UnsupportedOperationException("getParameter() not supported");
   837     }
   856     }
       
   857 
       
   858     // see JCA spec
       
   859     @Override
       
   860     protected AlgorithmParameters engineGetParameters() {
       
   861         return null;
       
   862     }
   838 }
   863 }