pindo 5.21.1 → 5.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8fc2d66a2010bba4e00fe508252a291bac2efda4623ded2135bf707b6f93ade0
|
|
4
|
+
data.tar.gz: cfca3acb943122590ffeba33d95249c2d73143b7e51ff87e74ef5342e44dd67f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 652bf861a3896a3763e38ff0f7142128dace9d221350db4a353b1f6ad22fd19dc5661ac926825438cf5dae7fdf287221b3888b8b84d6dccf6d54be024bac759b
|
|
7
|
+
data.tar.gz: bfd8a3891dc78f37fa1bccec6a67eb9dd7f6f8a4f4cac86d95788d0d64b63e938dd6385579ac3d0bc50141629bc236f2bf4a16d69f597b7036f8a1b497c03cb4
|
|
@@ -417,7 +417,7 @@ module Pindo
|
|
|
417
417
|
end
|
|
418
418
|
|
|
419
419
|
def install_certificate_to_keychain(cert_path:, key_path:, cert_password:)
|
|
420
|
-
P12Material.load(cert_path: cert_path, key_path: key_path, password: cert_password)
|
|
420
|
+
material = P12Material.load(cert_path: cert_path, key_path: key_path, password: cert_password)
|
|
421
421
|
unless Pindo::CertHelper.is_cert_valid?(cert_path)
|
|
422
422
|
raise Informative, "证书已经过期,请重新生成新证书!"
|
|
423
423
|
end
|
|
@@ -427,8 +427,19 @@ module Pindo
|
|
|
427
427
|
return if signing_identity_installed?(cert_path, keychain_path)
|
|
428
428
|
|
|
429
429
|
keychain_password = Pindoconfig.instance.cert_key_password
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
if material.is_a?(P12Material::PemMaterial)
|
|
431
|
+
# security 需要完整的证书与私钥;在受限目录中将 PEM 封装为 P12。
|
|
432
|
+
Dir.mktmpdir('pindo_pem_import_') do |directory|
|
|
433
|
+
import_path = File.join(directory, 'identity.p12')
|
|
434
|
+
p12 = OpenSSL::PKCS12.create(cert_password, 'pindo', material.key, material.certificate)
|
|
435
|
+
File.open(import_path, File::WRONLY | File::CREAT | File::EXCL, 0o600) { |file| file.write(p12.to_der) }
|
|
436
|
+
KeychainHelper.import_file(import_path, keychain_path,
|
|
437
|
+
keychain_password: keychain_password, certificate_password: cert_password, strict: true)
|
|
438
|
+
end
|
|
439
|
+
else
|
|
440
|
+
KeychainHelper.import_file(key_path, keychain_path,
|
|
441
|
+
keychain_password: keychain_password, certificate_password: cert_password, strict: true)
|
|
442
|
+
end
|
|
432
443
|
unless signing_identity_installed?(cert_path, keychain_path)
|
|
433
444
|
raise Informative, "钥匙串未出现证书与私钥组成的签名身份,请检查钥匙串访问权限"
|
|
434
445
|
end
|
|
@@ -4,8 +4,16 @@ module Pindo
|
|
|
4
4
|
module CertProcess
|
|
5
5
|
# Validate the freshly downloaded material before touching a user's keychain.
|
|
6
6
|
class P12Material
|
|
7
|
+
PemMaterial = Struct.new(:key, :certificate)
|
|
8
|
+
|
|
7
9
|
def self.load(cert_path:, key_path:, password:)
|
|
8
|
-
|
|
10
|
+
certificate = OpenSSL::X509::Certificate.new(File.binread(cert_path))
|
|
11
|
+
content = File.binread(key_path)
|
|
12
|
+
material = if content.include?('-----BEGIN ')
|
|
13
|
+
parse_pem(content, password, certificate)
|
|
14
|
+
else
|
|
15
|
+
parse(key_path, password)
|
|
16
|
+
end
|
|
9
17
|
unless material.key
|
|
10
18
|
raise Informative, 'P12 私钥缺失,请重新导出包含私钥的 P12', cause: nil
|
|
11
19
|
end
|
|
@@ -13,9 +21,8 @@ module Pindo
|
|
|
13
21
|
raise Informative, 'P12 证书缺失,请重新导出包含证书的 P12', cause: nil
|
|
14
22
|
end
|
|
15
23
|
|
|
16
|
-
certificate = OpenSSL::X509::Certificate.new(File.binread(cert_path))
|
|
17
24
|
unless material.certificate.to_der == certificate.to_der && certificate.check_private_key(material.key)
|
|
18
|
-
raise Informative, '
|
|
25
|
+
raise Informative, '私钥或证书与下载的 CER 证书不匹配,请更新同一套证书材料', cause: nil
|
|
19
26
|
end
|
|
20
27
|
material
|
|
21
28
|
rescue OpenSSL::X509::CertificateError, OpenSSL::PKey::PKeyError
|
|
@@ -24,6 +31,26 @@ module Pindo
|
|
|
24
31
|
raise Informative, '无法读取证书材料,请重新下载', cause: nil
|
|
25
32
|
end
|
|
26
33
|
|
|
34
|
+
def self.parse_pem(content, password, certificate)
|
|
35
|
+
unless content.match?(/-----BEGIN (?:RSA |EC |DSA |ENCRYPTED )?PRIVATE KEY-----/)
|
|
36
|
+
raise Informative, 'PEM 私钥缺失,请提供包含私钥的 PEM 文件', cause: nil
|
|
37
|
+
end
|
|
38
|
+
key = OpenSSL::PKey.read(content, password.to_s)
|
|
39
|
+
unless key.respond_to?(:private?) && key.private?
|
|
40
|
+
raise Informative, 'PEM 私钥缺失,请提供包含私钥的 PEM 文件', cause: nil
|
|
41
|
+
end
|
|
42
|
+
PemMaterial.new(key, certificate)
|
|
43
|
+
rescue OpenSSL::PKey::PKeyError => error
|
|
44
|
+
if error.message.match?(/unsupported|unknown cipher|unknown pbe|fetch failed|disabled|not supported/i)
|
|
45
|
+
raise Informative, 'PEM 加密算法不兼容当前 OpenSSL,请以现代算法重新导出', cause: nil
|
|
46
|
+
elsif content.include?('ENCRYPTED')
|
|
47
|
+
raise Informative, 'PEM 私钥解密失败,请检查导出密码及文件完整性', cause: nil
|
|
48
|
+
else
|
|
49
|
+
raise Informative, 'PEM 私钥格式无效或文件已损坏', cause: nil
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
private_class_method :parse_pem
|
|
53
|
+
|
|
27
54
|
def self.parse(key_path, password)
|
|
28
55
|
OpenSSL::PKCS12.new(File.binread(key_path), password)
|
|
29
56
|
rescue OpenSSL::PKCS12::PKCS12Error => error
|
data/lib/pindo/version.rb
CHANGED