请帮忙看看连接数据库密码加密方式不生效的问题,谢谢
我的配置如下:
canal版本:
com.alibaba.otter canal.client 1.1.4
用户名和密码
canal.instance.dbUsername=canal canal.instance.dbPassword=NWF3DPxKGGs+gj/XLdi6B269CTyLemfqagQg5D0nVMgPets7Zol6toOrbGLhMByRyQzkYUHWb9moSQiWrFZppw== canal.instance.connectionCharset = UTF-8
canal.instance.enableDruid=true canal.instance.pwdPublicKey=MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAocbCrurZGbC5GArEHKlAfDSZi7gFBnd4yxOt0rwTqKBFzGyhtQLu5PRKjEiOXVa95aeIIBJ6OhC2f8FjqFUpawIDAQABAkAPejKaBYHrwUqUEEOe8lpnB6lBAsQIUFnQI
但是启动instance报错: 2020-12-29 18:31:23.483 [canal-instance-scan-0] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal.properties] 2020-12-29 18:31:23.483 [canal-instance-scan-0] INFO c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Loading properties file from class path resource [canal_smart_transfer/instance.properties] 2020-12-29 18:31:23.484 [canal-instance-scan-0] WARN c.a.o.c.i.spring.support.PropertyPlaceholderConfigurer - Could not load properties from class path resource [canal_smart_transfer/instance.properties]: class path resource [canal_smart_transfer/instance.properties] cannot be opened because it does not exist 2020-12-29 18:31:23.490 [canal-instance-scan-0] WARN o.s.context.support.ClassPathXmlApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'instance' defined in class path resource [spring/file-instance.xml]: Cannot resolve reference to bean 'eventParser' while setting bean property 'eventParser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventParser' defined in class path resource [spring/file-instance.xml]: Cannot create inner bean 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' of type [com.alibaba.otter.canal.parse.support.AuthenticationInfo] while setting bean property 'masterInfo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key 2020-12-29 18:31:23.491 [canal-instance-scan-0] ERROR c.a.o.canal.instance.spring.SpringCanalInstanceGenerator - generator instance failed. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'instance' defined in class path resource [spring/file-instance.xml]: Cannot resolve reference to bean 'eventParser' while setting bean property 'eventParser'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventParser' defined in class path resource [spring/file-instance.xml]: Cannot create inner bean 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' of type [com.alibaba.otter.canal.parse.support.AuthenticationInfo] while setting bean property 'masterInfo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1419) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:638) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:942) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) ~[spring-context-3.2.18.RELEASE.jar:3.2.18.RELEASE] at com.alibaba.otter.canal.instance.manager.PlainCanalInstanceGenerator.getBeanFactory(PlainCanalInstanceGenerator.java:71) ~[canal.instance.manager-1.1.4.jar:na] at com.alibaba.otter.canal.instance.manager.PlainCanalInstanceGenerator.generate(PlainCanalInstanceGenerator.java:52) ~[canal.instance.manager-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.CanalController$5.generate(CanalController.java:388) [canal.deployer-1.1.4.jar:na] at com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded$1.apply(CanalServerWithEmbedded.java:85) [canal.server-1.1.4.jar:na] at com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded$1.apply(CanalServerWithEmbedded.java:82) [canal.server-1.1.4.jar:na] at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:356) [guava-18.0.jar:na] at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:182) [guava-18.0.jar:na] at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:151) [guava-18.0.jar:na] at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:67) [guava-18.0.jar:na] at com.google.common.collect.MapMaker$ComputingMapAdapter.get(MapMaker.java:885) [guava-18.0.jar:na] at com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded.start(CanalServerWithEmbedded.java:137) [canal.server-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.CanalController$2$1.processActiveEnter(CanalController.java:160) [canal.deployer-1.1.4.jar:na] at com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor.processActiveEnter(ServerRunningMonitor.java:247) [canal.common-1.1.4.jar:na] at com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor.start(ServerRunningMonitor.java:104) [canal.common-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.CanalController$3.start(CanalController.java:248) [canal.deployer-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.notifyStart(ManagerInstanceConfigMonitor.java:129) [canal.deployer-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.lambda$scan$3(ManagerInstanceConfigMonitor.java:122) [canal.deployer-1.1.4.jar:na] at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_242] at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.scan(ManagerInstanceConfigMonitor.java:121) [canal.deployer-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor.access$000(ManagerInstanceConfigMonitor.java:29) [canal.deployer-1.1.4.jar:na] at com.alibaba.otter.canal.deployer.monitor.ManagerInstanceConfigMonitor$2.run(ManagerInstanceConfigMonitor.java:53) ~[canal.deployer-1.1.4.jar:na] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_242] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) ~[na:1.8.0_242] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) ~[na:1.8.0_242] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) ~[na:1.8.0_242] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_242] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_242] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_242] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eventParser' defined in class path resource [spring/file-instance.xml]: Cannot create inner bean 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' of type [com.alibaba.otter.canal.parse.support.AuthenticationInfo] while setting bean property 'masterInfo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:287) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:122) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1419) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] ... 42 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.alibaba.otter.canal.parse.support.AuthenticationInfo#6a623670' defined in class path resource [spring/file-instance.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to get public key at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:276) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] ... 52 common frames omitted Caused by: java.lang.IllegalArgumentException: Failed to get public key at com.alibaba.druid.filter.config.ConfigTools.getPublicKey(ConfigTools.java:101) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.filter.config.ConfigTools.decrypt(ConfigTools.java:63) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.otter.canal.parse.support.AuthenticationInfo.initPwd(AuthenticationInfo.java:28) ~[canal.parse-1.1.4.jar:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_242] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_242] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_242] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_242] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1640) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1581) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1511) ~[spring-beans-3.2.18.RELEASE.jar:3.2.18.RELEASE] ... 55 common frames omitted Caused by: java.lang.IllegalArgumentException: String length must be a multiple of four. at com.alibaba.druid.util.Base64.base64ToByteArray(Base64.java:122) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.util.Base64.base64ToByteArray(Base64.java:107) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.filter.config.ConfigTools.getPublicKey(ConfigTools.java:94) ~[druid-1.1.9.jar:1.1.9] ... 64 common frames omitted
分析了一下代码,除了上面的bean加载失败的问题,感觉这个类的加解密也有点看不懂,是不是canal.instance.enableDruid配置成true这个功能不生效; com.alibaba.druid.filter.config.ConfigTools.java AuthenticationInfo.class 为什么解密用公钥呢? this.password = ConfigTools.decrypt(pwdPublicKey, password);
原提问者GitHub用户XuYijing2018
1、依赖Druid 实现工具类[ConfigTools]进行用户认证,即私钥进行签名,公钥进行认证(请先区分RSA 加密场景与RSA 签名场景)
2、从上面的报错来看,应该是传入的密码或公钥不对
3、详细生成公钥与密码方法,可参考以下DEMO
public static void main(String[] args) throws Exception {
String pwd = "123456";
// pair[0] -> privateKey
// pair[1] -> publicKey
String[] pair = ConfigTools.genKeyPair(512);
String privateKey = pair[0];
String publicKey = pair[1];
String enPwd = ConfigTools.encrypt(privateKey, pwd);
System.out.println("canal.instance.dbPassword=" + enPwd);
System.out.println("canal.instance.pwdPublicKey=" + publicKey);
System.out.println(ConfigTools.decrypt(publicKey, enPwd));
}
原回答者GitHub用户wingerx
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。