|
27 | 27 | using Keyfactor.PKI.PrivateKeys; |
28 | 28 | using Keyfactor.PKI.CryptographicObjects.Formatters; |
29 | 29 | using Org.BouncyCastle.X509; |
| 30 | +using Org.BouncyCastle.Asn1.Pkcs; |
30 | 31 |
|
31 | 32 | namespace Keyfactor.Extensions.Orchestrator.RemoteFile |
32 | 33 | { |
@@ -112,17 +113,50 @@ internal void LoadCertificateStore(ICertificateStoreSerializer certificateStoreS |
112 | 113 | { |
113 | 114 | logger.MethodEntry(LogLevel.Debug); |
114 | 115 |
|
| 116 | + Pkcs12StoreBuilder storeBuilder = new Pkcs12StoreBuilder(); |
| 117 | + CertificateStore = storeBuilder.Build(); |
| 118 | + |
115 | 119 | byte[] byteContents = RemoteHandler.DownloadCertificateFile(StorePath + StoreFileName); |
116 | | - Pkcs12Store CertificateStore = certificateStoreSerializer.DeserializeRemoteCertificateStore(byteContents, StorePath, StorePassword, RemoteHandler, isInventory); |
| 120 | + if (byteContents.Length < 5) |
| 121 | + return; |
| 122 | + |
| 123 | + CertificateStore = certificateStoreSerializer.DeserializeRemoteCertificateStore(byteContents, StorePath, StorePassword, RemoteHandler, isInventory); |
117 | 124 |
|
118 | 125 | logger.MethodExit(LogLevel.Debug); |
119 | 126 | } |
120 | 127 |
|
121 | | - internal Pkcs12Store GetCertificateStore() |
| 128 | + internal Pkcs12Store GetCertificateStore(bool requiresLegacyEncryption) |
122 | 129 | { |
123 | 130 | logger.MethodEntry(LogLevel.Debug); |
124 | 131 | logger.MethodExit(LogLevel.Debug); |
125 | 132 |
|
| 133 | + if (requiresLegacyEncryption) |
| 134 | + { |
| 135 | + Pkcs12StoreBuilder builder = new Pkcs12StoreBuilder(); |
| 136 | + builder.SetKeyAlgorithm(PkcsObjectIdentifiers.PbeWithShaAnd3KeyTripleDesCbc); |
| 137 | + builder.SetCertAlgorithm(PkcsObjectIdentifiers.PbewithShaAnd40BitRC2Cbc); |
| 138 | + |
| 139 | + Pkcs12Store tempStore = builder.Build(); |
| 140 | + |
| 141 | + foreach (string alias in CertificateStore.Aliases) |
| 142 | + { |
| 143 | + if (CertificateStore.IsKeyEntry(alias)) |
| 144 | + { |
| 145 | + var keyEntry = CertificateStore.GetKey(alias); |
| 146 | + var certChain = CertificateStore.GetCertificateChain(alias); |
| 147 | + |
| 148 | + tempStore.SetKeyEntry(alias, keyEntry, certChain); |
| 149 | + } |
| 150 | + else if (CertificateStore.IsCertificateEntry(alias)) |
| 151 | + { |
| 152 | + var certEntry = CertificateStore.GetCertificate(alias); |
| 153 | + tempStore.SetCertificateEntry(alias, certEntry); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + CertificateStore = tempStore; |
| 158 | + } |
| 159 | + |
126 | 160 | return CertificateStore; |
127 | 161 | } |
128 | 162 |
|
|
0 commit comments