提交 5bd8dd0e 编写于 作者: V vinnie

8056026: Debug security logging should print Provider used for each crypto operation

Reviewed-by: mullan
上级 c08f212f
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,7 @@ import java.security.Provider.Service; ...@@ -33,6 +33,7 @@ import java.security.Provider.Service;
import sun.security.jca.*; import sun.security.jca.*;
import sun.security.jca.GetInstance.Instance; import sun.security.jca.GetInstance.Instance;
import sun.security.util.Debug;
/** /**
* The KeyPairGenerator class is used to generate pairs of * The KeyPairGenerator class is used to generate pairs of
...@@ -126,6 +127,11 @@ import sun.security.jca.GetInstance.Instance; ...@@ -126,6 +127,11 @@ import sun.security.jca.GetInstance.Instance;
public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("keypairgenerator");
private final String algorithm; private final String algorithm;
// The provider // The provider
...@@ -167,6 +173,12 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { ...@@ -167,6 +173,12 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
kpg = new Delegate(spi, algorithm); kpg = new Delegate(spi, algorithm);
} }
kpg.provider = instance.provider; kpg.provider = instance.provider;
if (!skipDebug && pdebug != null) {
pdebug.println("KeyPairGenerator." + algorithm +
" algorithm from: " + kpg.provider.getName());
}
return kpg; return kpg;
} }
...@@ -557,6 +569,11 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi { ...@@ -557,6 +569,11 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
provider = instance.provider; provider = instance.provider;
this.serviceIterator = serviceIterator; this.serviceIterator = serviceIterator;
initType = I_NONE; initType = I_NONE;
if (!skipDebug && pdebug != null) {
pdebug.println("KeyPairGenerator." + algorithm +
" algorithm from: " + provider.getName());
}
} }
/** /**
......
...@@ -37,6 +37,8 @@ import javax.crypto.SecretKey; ...@@ -37,6 +37,8 @@ import javax.crypto.SecretKey;
import javax.security.auth.DestroyFailedException; import javax.security.auth.DestroyFailedException;
import javax.security.auth.callback.*; import javax.security.auth.callback.*;
import sun.security.util.Debug;
/** /**
* This class represents a storage facility for cryptographic * This class represents a storage facility for cryptographic
* keys and certificates. * keys and certificates.
...@@ -177,6 +179,11 @@ import javax.security.auth.callback.*; ...@@ -177,6 +179,11 @@ import javax.security.auth.callback.*;
public class KeyStore { public class KeyStore {
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("keystore");
/* /*
* Constant to lookup in the Security properties file to determine * Constant to lookup in the Security properties file to determine
* the default keystore type. * the default keystore type.
...@@ -801,6 +808,11 @@ public class KeyStore { ...@@ -801,6 +808,11 @@ public class KeyStore {
this.keyStoreSpi = keyStoreSpi; this.keyStoreSpi = keyStoreSpi;
this.provider = provider; this.provider = provider;
this.type = type; this.type = type;
if (!skipDebug && pdebug != null) {
pdebug.println("KeyStore." + type.toUpperCase() + " type from: " +
this.provider.getName());
}
} }
/** /**
......
...@@ -35,6 +35,8 @@ import java.io.ByteArrayInputStream; ...@@ -35,6 +35,8 @@ import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import sun.security.util.Debug;
/** /**
* This MessageDigest class provides applications the functionality of a * This MessageDigest class provides applications the functionality of a
* message digest algorithm, such as SHA-1 or SHA-256. * message digest algorithm, such as SHA-1 or SHA-256.
...@@ -103,6 +105,11 @@ import java.nio.ByteBuffer; ...@@ -103,6 +105,11 @@ import java.nio.ByteBuffer;
public abstract class MessageDigest extends MessageDigestSpi { public abstract class MessageDigest extends MessageDigestSpi {
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("messagedigest");
private String algorithm; private String algorithm;
// The state of this digest // The state of this digest
...@@ -156,18 +163,23 @@ public abstract class MessageDigest extends MessageDigestSpi { ...@@ -156,18 +163,23 @@ public abstract class MessageDigest extends MessageDigestSpi {
public static MessageDigest getInstance(String algorithm) public static MessageDigest getInstance(String algorithm)
throws NoSuchAlgorithmException { throws NoSuchAlgorithmException {
try { try {
MessageDigest md;
Object[] objs = Security.getImpl(algorithm, "MessageDigest", Object[] objs = Security.getImpl(algorithm, "MessageDigest",
(String)null); (String)null);
if (objs[0] instanceof MessageDigest) { if (objs[0] instanceof MessageDigest) {
MessageDigest md = (MessageDigest)objs[0]; md = (MessageDigest)objs[0];
md.provider = (Provider)objs[1];
return md;
} else { } else {
MessageDigest delegate = md = new Delegate((MessageDigestSpi)objs[0], algorithm);
new Delegate((MessageDigestSpi)objs[0], algorithm); }
delegate.provider = (Provider)objs[1]; md.provider = (Provider)objs[1];
return delegate;
if (!skipDebug && pdebug != null) {
pdebug.println("MessageDigest." + algorithm +
" algorithm from: " + md.provider.getName());
} }
return md;
} catch(NoSuchProviderException e) { } catch(NoSuchProviderException e) {
throw new NoSuchAlgorithmException(algorithm + " not found"); throw new NoSuchAlgorithmException(algorithm + " not found");
} }
......
...@@ -32,6 +32,7 @@ import java.security.Provider.Service; ...@@ -32,6 +32,7 @@ import java.security.Provider.Service;
import sun.security.jca.*; import sun.security.jca.*;
import sun.security.jca.GetInstance.Instance; import sun.security.jca.GetInstance.Instance;
import sun.security.util.Debug;
/** /**
* This class provides a cryptographically strong random number * This class provides a cryptographically strong random number
...@@ -92,6 +93,11 @@ import sun.security.jca.GetInstance.Instance; ...@@ -92,6 +93,11 @@ import sun.security.jca.GetInstance.Instance;
public class SecureRandom extends java.util.Random { public class SecureRandom extends java.util.Random {
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("securerandom");
/** /**
* The provider. * The provider.
* *
...@@ -234,6 +240,11 @@ public class SecureRandom extends java.util.Random { ...@@ -234,6 +240,11 @@ public class SecureRandom extends java.util.Random {
this.secureRandomSpi = secureRandomSpi; this.secureRandomSpi = secureRandomSpi;
this.provider = provider; this.provider = provider;
this.algorithm = algorithm; this.algorithm = algorithm;
if (!skipDebug && pdebug != null) {
pdebug.println("SecureRandom." + algorithm +
" algorithm from: " + this.provider.getName());
}
} }
/** /**
......
/* /*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -121,6 +121,11 @@ public abstract class Signature extends SignatureSpi { ...@@ -121,6 +121,11 @@ public abstract class Signature extends SignatureSpi {
private static final Debug debug = private static final Debug debug =
Debug.getInstance("jca", "Signature"); Debug.getInstance("jca", "Signature");
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("signature");
/* /*
* The algorithm for this signature object. * The algorithm for this signature object.
* This value is used to map an OID to the particular algorithm. * This value is used to map an OID to the particular algorithm.
...@@ -451,6 +456,11 @@ public abstract class Signature extends SignatureSpi { ...@@ -451,6 +456,11 @@ public abstract class Signature extends SignatureSpi {
throws InvalidKeyException { throws InvalidKeyException {
engineInitVerify(publicKey); engineInitVerify(publicKey);
state = VERIFY; state = VERIFY;
if (!skipDebug && pdebug != null) {
pdebug.println("Signature." + algorithm +
" verification algorithm from: " + this.provider.getName());
}
} }
/** /**
...@@ -495,6 +505,11 @@ public abstract class Signature extends SignatureSpi { ...@@ -495,6 +505,11 @@ public abstract class Signature extends SignatureSpi {
PublicKey publicKey = certificate.getPublicKey(); PublicKey publicKey = certificate.getPublicKey();
engineInitVerify(publicKey); engineInitVerify(publicKey);
state = VERIFY; state = VERIFY;
if (!skipDebug && pdebug != null) {
pdebug.println("Signature." + algorithm +
" verification algorithm from: " + this.provider.getName());
}
} }
/** /**
...@@ -511,6 +526,11 @@ public abstract class Signature extends SignatureSpi { ...@@ -511,6 +526,11 @@ public abstract class Signature extends SignatureSpi {
throws InvalidKeyException { throws InvalidKeyException {
engineInitSign(privateKey); engineInitSign(privateKey);
state = SIGN; state = SIGN;
if (!skipDebug && pdebug != null) {
pdebug.println("Signature." + algorithm +
" signing algorithm from: " + this.provider.getName());
}
} }
/** /**
...@@ -529,6 +549,11 @@ public abstract class Signature extends SignatureSpi { ...@@ -529,6 +549,11 @@ public abstract class Signature extends SignatureSpi {
throws InvalidKeyException { throws InvalidKeyException {
engineInitSign(privateKey, random); engineInitSign(privateKey, random);
state = SIGN; state = SIGN;
if (!skipDebug && pdebug != null) {
pdebug.println("Signature." + algorithm +
" signing algorithm from: " + this.provider.getName());
}
} }
/** /**
......
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -167,6 +167,11 @@ public class Cipher { ...@@ -167,6 +167,11 @@ public class Cipher {
private static final Debug debug = private static final Debug debug =
Debug.getInstance("jca", "Cipher"); Debug.getInstance("jca", "Cipher");
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("cipher");
/** /**
* Constant used to initialize cipher to encryption mode. * Constant used to initialize cipher to encryption mode.
*/ */
...@@ -1110,6 +1115,21 @@ public class Cipher { ...@@ -1110,6 +1115,21 @@ public class Cipher {
} }
} }
private static String getOpmodeString(int opmode) {
switch (opmode) {
case ENCRYPT_MODE:
return "encryption";
case DECRYPT_MODE:
return "decryption";
case WRAP_MODE:
return "key wrapping";
case UNWRAP_MODE:
return "key unwrapping";
default:
return "";
}
}
/** /**
* Initializes this cipher with a key. * Initializes this cipher with a key.
* *
...@@ -1235,6 +1255,12 @@ public class Cipher { ...@@ -1235,6 +1255,12 @@ public class Cipher {
initialized = true; initialized = true;
this.opmode = opmode; this.opmode = opmode;
if (!skipDebug && pdebug != null) {
pdebug.println("Cipher." + transformation + " " +
getOpmodeString(opmode) + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
...@@ -1372,6 +1398,12 @@ public class Cipher { ...@@ -1372,6 +1398,12 @@ public class Cipher {
initialized = true; initialized = true;
this.opmode = opmode; this.opmode = opmode;
if (!skipDebug && pdebug != null) {
pdebug.println("Cipher." + transformation + " " +
getOpmodeString(opmode) + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
...@@ -1509,6 +1541,12 @@ public class Cipher { ...@@ -1509,6 +1541,12 @@ public class Cipher {
initialized = true; initialized = true;
this.opmode = opmode; this.opmode = opmode;
if (!skipDebug && pdebug != null) {
pdebug.println("Cipher." + transformation + " " +
getOpmodeString(opmode) + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
...@@ -1693,6 +1731,12 @@ public class Cipher { ...@@ -1693,6 +1731,12 @@ public class Cipher {
initialized = true; initialized = true;
this.opmode = opmode; this.opmode = opmode;
if (!skipDebug && pdebug != null) {
pdebug.println("Cipher." + transformation + " " +
getOpmodeString(opmode) + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
......
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -78,6 +78,11 @@ public class KeyAgreement { ...@@ -78,6 +78,11 @@ public class KeyAgreement {
private static final Debug debug = private static final Debug debug =
Debug.getInstance("jca", "KeyAgreement"); Debug.getInstance("jca", "KeyAgreement");
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("keyagreement");
// The provider // The provider
private Provider provider; private Provider provider;
...@@ -468,6 +473,11 @@ public class KeyAgreement { ...@@ -468,6 +473,11 @@ public class KeyAgreement {
throw new InvalidKeyException(e); throw new InvalidKeyException(e);
} }
} }
if (!skipDebug && pdebug != null) {
pdebug.println("KeyAgreement." + algorithm + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
...@@ -524,6 +534,11 @@ public class KeyAgreement { ...@@ -524,6 +534,11 @@ public class KeyAgreement {
} else { } else {
chooseProvider(I_PARAMS, key, params, random); chooseProvider(I_PARAMS, key, params, random);
} }
if (!skipDebug && pdebug != null) {
pdebug.println("KeyAgreement." + algorithm + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
......
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,7 @@ import java.security.spec.*; ...@@ -33,6 +33,7 @@ import java.security.spec.*;
import sun.security.jca.*; import sun.security.jca.*;
import sun.security.jca.GetInstance.Instance; import sun.security.jca.GetInstance.Instance;
import sun.security.util.Debug;
/** /**
* This class provides the functionality of a secret (symmetric) key generator. * This class provides the functionality of a secret (symmetric) key generator.
...@@ -108,6 +109,11 @@ import sun.security.jca.GetInstance.Instance; ...@@ -108,6 +109,11 @@ import sun.security.jca.GetInstance.Instance;
public class KeyGenerator { public class KeyGenerator {
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("keygenerator");
// see java.security.KeyPairGenerator for failover notes // see java.security.KeyPairGenerator for failover notes
private final static int I_NONE = 1; private final static int I_NONE = 1;
...@@ -145,6 +151,11 @@ public class KeyGenerator { ...@@ -145,6 +151,11 @@ public class KeyGenerator {
this.spi = keyGenSpi; this.spi = keyGenSpi;
this.provider = provider; this.provider = provider;
this.algorithm = algorithm; this.algorithm = algorithm;
if (!skipDebug && pdebug != null) {
pdebug.println("KeyGenerator." + algorithm + " algorithm from: " +
this.provider.getName());
}
} }
private KeyGenerator(String algorithm) throws NoSuchAlgorithmException { private KeyGenerator(String algorithm) throws NoSuchAlgorithmException {
...@@ -158,6 +169,11 @@ public class KeyGenerator { ...@@ -158,6 +169,11 @@ public class KeyGenerator {
throw new NoSuchAlgorithmException throw new NoSuchAlgorithmException
(algorithm + " KeyGenerator not available"); (algorithm + " KeyGenerator not available");
} }
if (!skipDebug && pdebug != null) {
pdebug.println("KeyGenerator." + algorithm + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
......
/* /*
* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -77,6 +77,11 @@ public class Mac implements Cloneable { ...@@ -77,6 +77,11 @@ public class Mac implements Cloneable {
private static final Debug debug = private static final Debug debug =
Debug.getInstance("jca", "Mac"); Debug.getInstance("jca", "Mac");
private static final Debug pdebug =
Debug.getInstance("provider", "Provider");
private static final boolean skipDebug =
Debug.isOn("engine=") && !Debug.isOn("mac");
// The provider // The provider
private Provider provider; private Provider provider;
...@@ -413,6 +418,11 @@ public class Mac implements Cloneable { ...@@ -413,6 +418,11 @@ public class Mac implements Cloneable {
throw new InvalidKeyException("init() failed", e); throw new InvalidKeyException("init() failed", e);
} }
initialized = true; initialized = true;
if (!skipDebug && pdebug != null) {
pdebug.println("Mac." + algorithm + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
...@@ -435,6 +445,11 @@ public class Mac implements Cloneable { ...@@ -435,6 +445,11 @@ public class Mac implements Cloneable {
chooseProvider(key, params); chooseProvider(key, params);
} }
initialized = true; initialized = true;
if (!skipDebug && pdebug != null) {
pdebug.println("Mac." + algorithm + " algorithm from: " +
this.provider.getName());
}
} }
/** /**
......
/* /*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -104,7 +104,15 @@ public class Debug { ...@@ -104,7 +104,15 @@ public class Debug {
System.err.println("codebase=<URL>"); System.err.println("codebase=<URL>");
System.err.println(" only dump output if specified codebase"); System.err.println(" only dump output if specified codebase");
System.err.println(" is being checked"); System.err.println(" is being checked");
System.err.println();
System.err.println("The following can be used with provider:");
System.err.println();
System.err.println("engine=<engines>");
System.err.println(" only dump output for the specified list");
System.err.println(" of JCA engines. Supported values:");
System.err.println(" Cipher, KeyAgreement, KeyGenerator,");
System.err.println(" KeyPairGenerator, KeyStore, Mac,");
System.err.println(" MessageDigest, SecureRandom, Signature.");
System.err.println(); System.err.println();
System.err.println("Note: Separate multiple options with a comma"); System.err.println("Note: Separate multiple options with a comma");
System.exit(0); System.exit(0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册