2012-01-25 2 views
3

私はFIPS 140-2検証済み暗号化を必要とするプロジェクトに取り組んでおり、NSPをSunPKCS11トークンインターフェイスで使用しようとしています。 NSSのFIPSモードを有効にするまでCKR_USER_NOT_LOGGED_INというエラーが表示されますが、これはどうしたらいいのか分かりません。私が何をすべきかについての示唆は何ですか?JavaでNSSを使用してSunPKCS11を使用してFIPSモードを有効にしようとしています

セキュリティコードは、Oracle Javaチュートリアルのサンプル、SunPKCS11のリファレンスページ、Web上のFIPSモードでNSSを使用するための推奨事項をまとめたものです。

はここで私が使用しているコードです:

String ksName = "my.pfx"; 
char[] spass = {'m', 'y', 'p', 'w' }; 
String alias = "testalias"; 
try { 
    KeyStore ks = KeyStore.getInstance("PKCS12"); 
    FileInputStream ksfis = new FileInputStream(ksName); 
    BufferedInputStream ksbufin = new BufferedInputStream(ksfis); 
    ks.load(ksbufin, spass); 
    PrivateKey priv = (PrivateKey) ks.getKey(alias, spass); 

    System.out.println(" Initialize the signing."); 
    Signature sig = Signature.getInstance("SHA1withRSA", "SunPKCS11-NSS-FIPS"); 
    sig.initSign(priv); 

    System.out.println(" Open the digital object to sign."); 
    FileInputStream fis = new FileInputStream("digitalRecipes2.txt"); 
    BufferedInputStream bufin = new BufferedInputStream(fis); 
    byte[] buffer = new byte[1024]; 
    int len; 
    while ((len = bufin.read(buffer)) >= 0) { 
     sig.update(buffer, 0, len); 
    } 
    bufin.close(); 

    byte[] realSig = sig.sign(); 

    FileOutputStream sigfos = new FileOutputStream("digitalRecipes2.txt.sig"); 
    sigfos.write(realSig); 
    sigfos.close(); 

    java.security.cert.Certificate cert = ks.getCertificate(alias); 
    byte[] encodedCert = cert.getEncoded(); 

    FileOutputStream certfos = new FileOutputStream("mykey.cert"); 
    certfos.write(encodedCert); 
    certfos.close();  
} catch (Exception e) { 
    System.err.println("Caught exception " + e.toString()); 
    e.printStackTrace(); 
} 

と、ここで私はNSSのために使用している設定です。

name = NSS-FIPS 
nssLibraryDirectory = /opt/local/lib/nss 
nssSecmodDirectory = /Users/xxxx/work/workspace/learnin/XXXX 
nssDbMode = readWrite 
nssModule = fips 

このコードを実行すると、次のスタックトレースが取得されます。

Initialize the signing. 
Caught exception java.security.InvalidKeyException: Could not create RSA private key 
java.security.InvalidKeyException: Could not create RSA private key 
    at  sun.security.pkcs11.P11RSAKeyFactory.implTranslatePrivateKey(P11RSAKeyFactory.java:88) 
    at sun.security.pkcs11.P11KeyFactory.engineTranslateKey(P11KeyFactory.java:115) 
    at sun.security.pkcs11.P11KeyFactory.convertKey(P11KeyFactory.java:48) 
    at sun.security.pkcs11.P11Signature.engineInitSign(P11Signature.java:374) 
    at java.security.Signature$Delegate.engineInitSign(Signature.java:1095) 
    at java.security.Signature.initSign(Signature.java:480) 
    at  com.xxxxxxxx.digitalSigning.SignMeUpSunPKCS11NSS.main(SignMeUpSunPKCS11NSS.java:43) 
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_USER_NOT_LOGGED_IN 
    at sun.security.pkcs11.wrapper.PKCS11.C_CreateObject(Native Method) 
    at sun.security.pkcs11.P11RSAKeyFactory.generatePrivate(P11RSAKeyFactory.java:238) 
    at  sun.security.pkcs11.P11RSAKeyFactory.implTranslatePrivateKey(P11RSAKeyFactory.java:62) 
    ... 6 more 

、それは私が何を行うには見当がつかないCKR_USER_NOT_LOGGED_INエラーです。

FIPSモードを使用しないようにNSS設定を変更すると、プログラムは正常に動作し、ファイルに署名し、署名を与え、公開鍵を与えます。

NSS設定ファイルに記載されている適切なディレクトリにある間に、次のコマンドを使用してNSSデータベースを作成しました。

modutil -create -dbdir . 
modutil -fips true -dbdir . 
modutil -changepw "NSS FIPS 140-2 Certificate DB" -dbdir . 

答えて

関連する問題