You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. $Data = array();
  3. $Data[] = "[ req ]";
  4. $Data[] = "req_extensions = req_ext";
  5. $Data[] = "subjectAltName = @alt_names";
  6. $Data[] = "authorityKeyIdentifier = keyid,issuer";
  7. $Data[] = "basicConstraints = CA:FALSE";
  8. $Data[] = "distinguished_name = req_distinguished_name";
  9. $Data[] = "prompt = no";
  10. $Data[] = "[ req_distinguished_name ]";
  11. $Data[] = "commonName=Argus Sensor Module";
  12. $Data[] = "[ req_ext ]";
  13. $Data[] = "subjectAltName = @alt_names";
  14. $Data[] = "[ alt_names ]";
  15. $IPS = array();
  16. $IPS[] = "10.0.0.1";
  17. if( count( $argv ) > 1 ){
  18. $TMP = md5(time());
  19. $FD = fopen( $TMP.".conf", "w+" );
  20. if( $FD ){
  21. for( $i = 1; $i < count( $argv ); $i++ ){
  22. $IPS[] = $argv[$i];
  23. };
  24. $OIP = array();
  25. $CC = 1;
  26. foreach( $IPS as $I ){
  27. $OIP[] = 'IP.'.$CC.' = '.$I;
  28. $CC++;
  29. };
  30. $JJ = implode( "\n", $Data ) . "\n";
  31. fprintf( $FD, $JJ );
  32. $JJ = implode( "\n", $OIP ) . "\n";
  33. fprintf( $FD, $JJ );
  34. fclose( $FD );
  35. if( 0 ){
  36. $L = `openssl genrsa -out {$TMP}.key 2048`;
  37. $L = `openssl req -sha256 -verbose -config {$TMP}.conf -extensions req_ext -new -nodes -key {$TMP}.key -out {$TMP}.csr`;
  38. } else {
  39. $L = `openssl req -sha256 -verbose -config {$TMP}.conf -extensions req_ext -new -nodes -key host.key -out {$TMP}.csr`;
  40. };
  41. $L = `openssl x509 -req -CA rootCA.crt -CAkey rootCA.key -in {$TMP}.csr -out {$TMP}.crt -days 365 -CAcreateserial -extfile {$TMP}.conf -extensions req_ext`;
  42. unlink( $TMP . '.conf' );
  43. unlink( $TMP . '.csr' );
  44. };
  45. };
  46. ?>