2013-06-27 1 views
0

phpseclib로 서명하는 인증서에 SSL 서버 및 SSL 클라이언트 플래그를 추가하고 싶습니다. 어떻게해야합니까? setExtension 함수를 찾았지만 사용법을 모른다. 감사합니다. 감사합니다.phpseclib로 extKeyUsage를 어떻게 설정합니까?

나는 시도 한 (대부분 phpseclib 예에서) 다음과 나던 작업 : 현재 먼저 X.509의 인증서입니다 작성해야 할 것입니다 무엇


// create private key for CA cert 
$CAPrivKey = new Crypt_RSA(); 
extract($CAPrivKey->createKey()); 
$CAPrivKey->loadKey($privatekey); 

$pubKey = new Crypt_RSA(); 
$pubKey->loadKey($publickey); 
$pubKey->setPublicKey(); 

echo "the private key for the CA cert (can be discarded):\r\n\r\n"; 
echo $privatekey; 
echo "\r\n\r\n"; 


// create a self-signed cert that'll serve as the CA 
$subject = new File_X509(); 
$subject->setPublicKey($pubKey); 
$subject->setDNProp('id-at-organizationName', 'phpseclib demo CA'); 

$issuer = new File_X509(); 
$issuer->setPrivateKey($CAPrivKey); 
$issuer->setDN($CASubject = $subject->getDN()); 

$x509 = new File_X509(); 
$x509->setStartDate('-1 month'); 
$x509->setEndDate('+1 year'); 
$x509->setSerialNumber(chr(1)); 
$x509->makeCA(); 

$result = $x509->sign($issuer, $subject); 
echo "the CA cert to be imported into the browser is as follows:\r\n\r\n"; 
echo $x509->saveX509($result); 
echo "\r\n\r\n"; 


// create private key/x.509 cert for stunnel/website 
$privKey = new Crypt_RSA(); 
extract($privKey->createKey()); 
$privKey->loadKey($privatekey); 

$pubKey = new Crypt_RSA(); 
$pubKey->loadKey($publickey); 
$pubKey->setPublicKey(); 

$subject = new File_X509(); 
$subject->setPublicKey($pubKey); 
$subject->setDNProp('id-at-organizationName', 'phpseclib demo cert'); 
$subject->setDomain('www.google.com'); 

$issuer = new File_X509(); 
$issuer->setPrivateKey($CAPrivKey); 
$issuer->setDN($CASubject); 

$x509 = new File_X509(); 
$x509->setStartDate('-1 month'); 
$x509->setEndDate('+1 year'); 
$x509->setSerialNumber(chr(1)); 
$x509->setExtension('id-ce-extKeyUsage', array('id-kp-serverAuth', 'id-kp-clientAuth')); 

$result = $x509->sign($issuer, $subject); 

echo "the stunnel.pem contents are as follows:\r\n\r\n"; 
echo $privKey->getPrivateKey(); 
echo "\r\n"; 
echo $x509->saveX509($result); 
echo "\r\n"; 

답변

1

이의에 확장을 추가 X.509 인증서를 만든 다음 다시 서명하십시오. 예.

$result = $x509->sign($issuer, $subject); 후이 작업을 수행 :

$x509->loadX509($result); 

$x509->setExtension('id-ce-extKeyUsage', array('id-kp-serverAuth', 'id-kp-clientAuth')); 

$result = $x509->sign($issuer, $x509); 

즉. 당신은 인증서에 서명하고, 그것을로드하고, 확장을 설정 한 다음 사임합니다.

불행히도 우아한 해결책은 아닙니다. 어떤 점에서는 API가 처음에는 인증서를 가지고 있지 않아도 확장 프로그램을 업데이트 할 수 있도록 업데이트되지만 아직까지는 발생하지 않은 것으로 알고 있습니다.

관련 문제