SHARE
TWEET

Untitled

a guest Nov 27th, 2014 532 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?PHP
  2.     if(isset($_POST['key'])){
  3.         header('Content-type: application/x-x509-user-cert');
  4.         header('Content-disposition: attachment; filename=user.crt');
  5.         include('File/X509.php');
  6.  
  7.         $capem = '-----BEGIN CERTIFICATE-----
  8. MIIBzzCCATqgAwIBAgIBATALBgkqhkiG9w0BAQUwHDEaMBgGA1UECgwRcGhwc2VjbGliIGRlbW8g
  9. Q0EwIhgPMjAxMjA1MDQwMzQxNDhaGA8yMDEzMDYwNDAzNDE0OFowHDEaMBgGA1UECgwRcGhwc2Vj
  10. bGliIGRlbW8gQ0EwgZ0wCwYJKoZIhvcNAQEBA4GNADCBiQKBgQCeSAGfM4nHdIaBwThHYGW3MABT
  11. vrSMrawnGN/Mx5ttyLQF4YcUJFSpGAJ8y2hViak3irbLtc6nlpJFOHtMB4VsuG7S+MySYKBm5l7e
  12. ApfWynHMLKVml3URXCMVMXju4SxiI+D10nNOaq+eSEIFlPOY+7LgSdIAka6/9+z2hgoITQIDAQAB
  13. oyMwITAOBgNVHQ8BAQAEBAMCAQYwDwYDVR0TAQH/BAUwAwEB/zALBgkqhkiG9w0BAQUDgYEAc31s
  14. EL3tWfwFIHYK+96wzvAS7F/4FCMcZOdrW9LZ1IniXUSf601MIOVy0pAc17Xf6QjlVOhziA3cLMi3
  15. 3CWwEDgnhXU8s6YRAa6WD8eeHwmJKE3vIU0+klscIdOO+14BrC+mRUoPaZ1hmixMvrK/pVhXAkef
  16. XTSk5kq9f2Bfm+M=
  17. -----END CERTIFICATE-----';
  18.  
  19.         $subject = new File_X509();
  20.         $subject->loadCA($capem);
  21.         $subject->loadSPKAC($_POST['key']);
  22.         $subject->setDN('CN=Username');
  23.  
  24.         $issuer = new File_X509();
  25.         $issuer->loadX509($capem);
  26.         $cakey = new Crypt_RSA();
  27.         $cakey->loadKey('-----BEGIN RSA PRIVATE KEY-----
  28. MIICXAIBAAKBgQCeSAGfM4nHdIaBwThHYGW3MABTvrSMrawnGN/Mx5ttyLQF4YcUJFSpGAJ8y2hV
  29. iak3irbLtc6nlpJFOHtMB4VsuG7S+MySYKBm5l7eApfWynHMLKVml3URXCMVMXju4SxiI+D10nNO
  30. aq+eSEIFlPOY+7LgSdIAka6/9+z2hgoITQIDAQABAoGADS1RdT+FKOW6jPLZDJgp36ZPYKlvvoZ2
  31. 3opjl1jGx8z9r7+mzzZ3Fdy52EnW1cgwHj+eGDd6jNksNDcPjLTTlqfwoKMZhf1gpYBKA5PtnqFU
  32. rxM5eW3SzLWkPOZoS/i8fxze0uvoh0zcm6u1nictcjkj0Hqql4hbTrDRENxTfgECQQC9qYFWsH8q
  33. r/ztbl6WBxW1NT9JgthvteiINpAjeN9tmuP9BgTGPk4j3MhTVsPp5ogzdn3MLch2YJ9cJuEeHon1
  34. AkEA1aSiiZwGH9tCI8EFJrDqbCqDgeOmlkgMp5YQ8TqBg6/nkM4wWz9cXSmFPO3L9BQhvXE8RlGJ
  35. DChCksbBcjnV+QJBALXZ7w+lz2iosYUejEahqGjFE1dyw//olXr1hiLc5K39E5kpyi4i012Ddfii
  36. etqsle9yL5A0Xb9TSblb9gGhGnkCQDyj8Gay3KIqMAnJ/dZPnRp6rr0titlZNg5TcBeojZ59TXMy
  37. s1MTFvpykJkMvjlXhYQqIfurpQTIYK0csUfk1rECQBPVqVAG45VBn6yV1cDaqvg/0aQ6yZc7nQTr
  38. 7aLuUCTaf/xP4wSWiQpGiRFdTLt3pkkI3XdngV6j8RCcpgED6qU=
  39. -----END RSA PRIVATE KEY-----');
  40.         $issuer->setPrivateKey($cakey);
  41.  
  42.         $x509 = new File_X509();
  43.         $cert = $x509->sign($issuer, $subject);
  44.  
  45.         $x509->loadX509($cert);
  46. $x509->setExtension('id-ce-keyUsage', array('digitalSignature', 'keyEncipherment', 'dataEncipherment'));
  47. $x509->setExtension('id-ce-extKeyUsage', array('id-kp-serverAuth', 'id-kp-clientAuth'));
  48.         $x509->setStartDate('-1 day');
  49.         $x509->setEndDate('+ 3 year');
  50.         $x509->setSerialNumber('12356', 10);
  51.         $cert = $x509->sign($issuer, $x509);
  52.  
  53.         echo $x509->saveX509($cert);
  54.     }else{
  55. ?>
  56. <form method="POST">
  57.     <keygen name="key" keytype="RSA" challenge="ucert">
  58.     <button>SEND</button>
  59. </form>
  60. <?PHP
  61.     }
  62. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top