我正在尝试使用Mule对PGP进行加密,但我收到的“publicKey不应为null”错误。
我在这里替换了local_policy.jar和US_export_policy.jar:C:\ Program Files \ Java \ jdk1.7.0_45 \ jre \ lib \ security
在我的图书馆中我有:bcpg-jdk15on-150.jar。我还添加了local_policy.jar(不确定我是否需要它,但我尝试使用和不使用并得到相同的错误)。
我正在运行MuleStudio 3.5和CE-3.4运行时。
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:pgp="http://www.mulesoft.org/schema/mule/pgp" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.4.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/pgp http://www.mulesoft.org/schema/mule/pgp/current/mule-pgp.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
<jms:activemq-connector name="Active_MQ" specification="1.1" username="removed" password="removed" brokerURL="tcp://127.0.0.1:61613" validateConnections="true" doc:name="Active MQ"/>
<spring:beans>
<spring:bean id="pgpKeyManager" class="org.mule.module.pgp.PGPKeyRingImpl" init-method="initialise">
<spring:property name="publicKeyRingFileName" value="pubring.gpg"/>
<spring:property name="secretKeyRingFileName" value="secring.gpg"/>
<spring:property name="secretAliasId" value="-2461745123444227218"/>
<spring:property name="secretPassphrase" value="removed"/>
</spring:bean>
<spring:bean id="credentialAccessor" class="org.mule.security.MuleHeaderCredentialsAccessor"/>
</spring:beans>
<pgp:security-manager>
<pgp:security-provider name="pgpSecurityProvider" keyManager-ref="pgpKeyManager" />
<pgp:keybased-encryption-strategy name="keyBasedEncryptionStrategy" keyManager-ref="pgpKeyManager" credentialsAccessor-ref="credentialAccessor" />
</pgp:security-manager>
<flow name="activemq_password_encryptionFlow1" doc:name="activemq_password_encryptionFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
<encrypt-transformer strategy-ref="keyBasedEncryptionStrategy" />
<jms:outbound-endpoint queue="test" connector-ref="Active_MQ" doc:name="JMS"/>
<echo-component doc:name="Echo"/>
</flow>
这是错误:
INFO 2014-03-10 14:44:04,480 [[activemq_password_encryption].connector.http.mule.default.receiver.02] org.mule.component.simple.LogComponent:
********************************************************************************
* Message received in service: activemq_password_encryptionFlow1. Content is: *
* '/helloworld2' *
********************************************************************************
ERROR 2014-03-10 14:44:04,489 [[activemq_password_encryption].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Crypto Failure
Code : MULE_ERROR-111
--------------------------------------------------------------------------------
Exception stack is:
1. The publicKey should not be null (java.lang.IllegalArgumentException)
org.apache.commons.lang.Validate:203 (null)
2. Crypto Failure (org.mule.api.security.CryptoFailureException)
org.mule.module.pgp.KeyBasedEncryptionStrategy:65 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/CryptoFailureException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalArgumentException: The publicKey should not be null
at org.apache.commons.lang.Validate.notNull(Validate.java:203)
at org.mule.module.pgp.EncryptStreamTransformer.<init>(EncryptStreamTransformer.java:46)
at org.mule.module.pgp.KeyBasedEncryptionStrategy.encrypt(KeyBasedEncryptionStrategy.java:60)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
答案 0 :(得分:0)
由于您使用的是MuleHeaderCredentialsAccessor并且尚未设置标头MULE_USER,或者它被设置为与密钥环中的任何uid都不匹配的值,因此会发生异常。
您必须设置此标头(入站属性)或实现自己的CredentialsAccessor,以返回正确的凭据。
您可以找到MuleHeaderCredentialsAccessor的代码,在this page上可以找到一个返回硬编码凭据的简单示例CredentialsAccessor。
答案 1 :(得分:0)
我得到了解决。请检查credentialAccessor
的{{1}}值以及导入的pgp密钥集。简单的方法是调试方法credentials
上的org.mule.module.pgp.KeyBasedEncryptionStrategy
行private PGPCryptInfo safeGetCryptInfo(Object cryptInfo)
将为您导入的密钥及其凭据来自您导入的流和密钥。