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 | # Genracja CA # {hex}30030101FF => ASN.1 BasicConstraints: CA:TRUE # $asn1=([System.Security.Cryptography.X509Certificates.X509BasicConstraintsExtension]::new($true, $flase, 0,$true)).RawData # $asn1 | Format-Hex -Encoding Ascii $ca_params =@{ "Type" = "Custom" ; "Subject" = "CN=Local CA" ; "FriendlyName" = "Local CA" ; "KeyAlgorithm" = "RSA" ; "KeyLength" = 2048; "KeyUsage" = "CertSign" ; "TextExtension" = @( "2.5.29.19={critical}{hex}30030101FF" ); "NotAfter" = (( Get-Date ).AddYears(10)); "CertStoreLocation" = "Cert:\CurrentUser\My" ; } $root =New -SelfSignedCertificate @ca_params $root .ToString() $cert_params =@{ "Signer" = $root ; "Type" = "CodeSigningCert" ; "Subject" = "CN=Robert Socha" ; "FriendlyName" = "Robert Socha CS" ; "KeyAlgorithm" = "RSA" ; "KeyLength" = 2048; "KeyUsage" = "DigitalSignature" ; "NotAfter" = (( Get-Date ).AddYears(10)); "CertStoreLocation" = "Cert:\CurrentUser\My" ; } # Generacja certyfikatu do podpisywania kodu $code =New -SelfSignedCertificate @cert_params $code .ToString() # Export certifkatu CA do zaufanych $ca_file = [System.IO.Path]::GetTempFileName() Export -Certificate -Type CERT -Cert $root -FilePath $ca_file -Force Import -Certificate -CertStoreLocation Cert:\CurrentUser\Root -FilePath $ca_file # Export certyfikatu podpisującego do zaufanych dostawców kodu Export -Certificate -Type CERT -Cert $code -FilePath $ca_file -Force Import -Certificate -CertStoreLocation Cert:\CurrentUser\TrustedPublisher -FilePath $ca_file Remove-Item $ca_file # $code=(Get-ChildItem cert:\CurrentUser\my -CodeSigningCert)[0] # Skrypt do podpisania 'Write-Host "Hello, World!"' >.\sign_me.ps1 # https:/go.microsoft.com/fwlink/?LinkID=135170 Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser -Force # Wartość domyślna dla wersji kliencikich Windows # Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser -Force Set-AuthenticodeSignature .\sign_me.ps1 $code .\sign_me.ps1 |
piątek, 25 stycznia 2019
PowerShell - podpisywanie skryptów (self-signed cert)
Time-Stamp Protocol (RFC 3161) + openssl
Serwery TSP:
Plik odpowiedzi. Dla pliku data-cert.tsr wygląda tak samo (różni się tylko rozmiar pliku)
man openssl ts
man openssl tsget
1 2 3 4 5 6 | # Plik z danymi: echo "Hello, World!" >data.txt # Tworzenie zapytania openssl ts -query -data data.txt -no_nonce -sha512 -out data.tsq openssl ts -query - in data.tsq -text |
Version: 1
Hash Algorithm: sha512
Message data:
0000 - 92 16 18 bc 6d 9f 80 59-43 7c 5e 03 97 b1 3f 97 ....m..YC|^...?.
0010 - 3a b7 c7 a7 b8 1f 0c a3-1b 70 bf 44 8f d8 00 a4 :........p.D....
0020 - 60 b6 7e fd a0 02 00 88-bc 97 bf 7d 9d a9 7a 9e `.~........}..z.
0030 - 2c e7 b2 0d 46 e0 66 46-2e c4 4c f6 02 84 f9 a7 ,...F.fF..L.....
Policy OID: unspecified
Nonce: unspecified
Certificate required: no
Extensions:
1 2 3 | # Zapytanie z żądaniem certyfikatu podpisującego openssl ts -query -data data.txt -no_nonce -sha512 -cert -out data-cert.tsq openssl ts -query - in data-cert.tsq -text |
Version: 1
Hash Algorithm: sha512
Message data:
0000 - 92 16 18 bc 6d 9f 80 59-43 7c 5e 03 97 b1 3f 97 ....m..YC|^...?.
0010 - 3a b7 c7 a7 b8 1f 0c a3-1b 70 bf 44 8f d8 00 a4 :........p.D....
0020 - 60 b6 7e fd a0 02 00 88-bc 97 bf 7d 9d a9 7a 9e `.~........}..z.
0030 - 2c e7 b2 0d 46 e0 66 46-2e c4 4c f6 02 84 f9 a7 ,...F.fF..L.....
Policy OID: unspecified
Nonce: unspecified
Certificate required: yes
Extensions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Wysyłanie zapytania do serwera curl -s -H "Content-Type: application/timestamp-query" \ --data-binary @data.tsq \ http: //time .certum.pl -o data.tsr curl -s -H "Content-Type: application/timestamp-query" \ --data-binary @data-cert.tsq \ http: //time .certum.pl -o data-cert.tsr # Lub wykorzystując tsget # Może być konieczna instalacja bindingów curla dla perla: apt-get install libwww-curl-perl /usr/lib/ssl/misc/tsget -h http: //time .certum.pl/ -e .tsr - v data.tsr data-cert.tsq #> data.tsr: sending request, reply received, ./data.tsr written. #> data-cert.tsq: sending request, reply received, ./data-cert.tsr written. # Informację na temat odpowiedzi openssl ts -reply - in data.tsr -text |
Pobieramy certyfikaty CA i pośredni (wymagany dla pliku data.tsr) z tej strony: https://www.certum.pl/pl/wsparcie/cert_wiedza_zaswiadczenia_klucze_certum/
Status info:
Status: Granted.
Status description: unspecified
Failure info: unspecified
TST info:
Version: 1
Policy OID: 1.2.616.1.113527.2.5.1.11
Hash Algorithm: sha512
Message data:
0000 - 92 16 18 bc 6d 9f 80 59-43 7c 5e 03 97 b1 3f 97 ....m..YC|^...?.
0010 - 3a b7 c7 a7 b8 1f 0c a3-1b 70 bf 44 8f d8 00 a4 :........p.D....
0020 - 60 b6 7e fd a0 02 00 88-bc 97 bf 7d 9d a9 7a 9e `.~........}..z.
0030 - 2c e7 b2 0d 46 e0 66 46-2e c4 4c f6 02 84 f9 a7 ,...F.fF..L.....
Serial number: 0x038D7EAE927662
Time stamp: Jan 25 00:17:48 2019 GMT
Accuracy: 0x01 seconds, unspecified millis, unspecified micros
Ordering: no
Nonce: unspecified
TSA: DirName:/C=PL/O=Unizeto Technologies S.A./OU=Certum Certification Authority/CN=Certum EV TSA SHA2
Extensions:
1 2 3 4 5 6 7 8 | wget https: //www .certum.pl /CTNCA .pem wget https: //www .certum.pl /pl/upload_module/wysiwyg/zaswiadczenia/Certum_EV_TSA_SHA2/TSA-SHA2 .pem # Weryfikacja # Odpowiedź z certyfikatem klucza podpisującego openssl ts -verify -data data.txt - in data-cert.tsr -CAfile CTNCA.pem # Odpowiedź bez certyfikatów openssl ts -verify -data data.txt - in data.tsr -CAfile CTNCA.pem -untrusted TSA-SHA2.pem |
man openssl ts
man openssl tsget
Subskrybuj:
Posty (Atom)