Repository navigation
Expand file tree
/
Copy pathCASignCert.php
More file actions
96 lines (68 loc) · 2.23 KB
/
Copy pathCASignCert.php
File metadata and controls
96 lines (68 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Created by PhpStorm.
* User: abcdlzy
* Date: 15/2/3
* Time: 上午11:00
*/
//根证书管理
include_once(dirname(__FILE__).'/File/X509.php');
include_once(dirname(__FILE__).'/Crypt/RSA.php');
include_once(dirname(__FILE__).'/config.php');
include_once(dirname(__FILE__) . '/configOperator.php');
function CreateNewCA(){
if(!$GLOBALS['isCA']){
return false;
}
// CA私钥
$CAPrivKey = new Crypt_RSA();
$keyArray=$CAPrivKey->createKey($GLOBALS['RSALength']);
$CAPrivKey->loadKey($keyArray['privatekey']);
$pubKey = new Crypt_RSA();
$pubKey->loadKey($keyArray['publickey']);
$pubKey->setPublicKey();
// CA 公钥 x509
$subject = new File_X509();
$subject->setDNProp('id-at-organizationName', $GLOBALS['CAname'].' CA');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CASubject = $subject->getDN());
$x509 = new File_X509();
$x509->makeCA();
$result = $x509->sign($issuer, $subject);
setConfig_CAPublishX509($x509->saveX509($result));
setConfig_CAPrivateKey($keyArray['privatekey']);
return true;
}
function signNewCert(){
if(!$GLOBALS['isCA']){
return false;
}
else {
$CAPrivKey = new Crypt_RSA();
$CAPrivKey->loadKey($GLOBALS['CAPrivKeyStr']);
$CAx509 = new File_X509();
$CAx509->loadX509($GLOBALS['CAPubX509']);
//认证证书
$privKey = new Crypt_RSA();
$keyArray = $CAPrivKey->createKey($GLOBALS['RSALength']);
$privKey->loadKey($keyArray['privatekey']);
$pubKey = new Crypt_RSA();
$pubKey->loadKey($keyArray['publickey']);
$pubKey->setPublicKey();
$subject = new File_X509();
$subject->setDNProp('id-at-organizationName', $GLOBALS['CAname'] . ' cert');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CAx509->getDN());
$x509 = new File_X509();
$result = $x509->sign($issuer, $subject);
return array(
'privateKey' => $privKey->getPrivateKey(),
'publicX509' => $x509->saveX509($result)
);
}
}
?>