Skip to content
Snippets Groups Projects
Unverified Commit 7b5216d2 authored by Max Adamo's avatar Max Adamo
Browse files

rollback attempt to use crypt library

parent 8bab8ad5
Branches
Tags
No related merge requests found
...@@ -30,17 +30,17 @@ if [ $? -gt 0 ]; then ...@@ -30,17 +30,17 @@ if [ $? -gt 0 ]; then
fi fi
echo "" echo ""
while true; do #while true; do
read -p "Do you wish to run upx against ${BIN_NAME}? (y/n) " yn # read -p "Do you wish to run upx against ${BIN_NAME}? (y/n) " yn
case $yn in # case $yn in
[Yy]*) # [Yy]*)
echo "" # echo ""
run_upx # run_upx
break # break
;; # ;;
[Nn]*) break ;; # [Nn]*) break ;;
*) echo "Please answer yes or no." ;; # *) echo "Please answer yes or no." ;;
esac # esac
done #done
echo -e "\nthe binary was compiled and it is avilable as:\n - ${GOPATH}/bin/${BIN_NAME}\n" echo -e "\nthe binary was compiled and it is avilable as:\n - ${GOPATH}/bin/${BIN_NAME}\n"
...@@ -40,6 +40,8 @@ var ( ...@@ -40,6 +40,8 @@ var (
tmpKeyDestination string tmpKeyDestination string
certTmpDir string certTmpDir string
opensslBinary string opensslBinary string
key *x509.Certificate
cert *x509.Certificate
) )
// app clean and exit // app clean and exit
...@@ -111,6 +113,7 @@ func checkCertificates(dnsname string, certificate string, fullchain string, ca ...@@ -111,6 +113,7 @@ func checkCertificates(dnsname string, certificate string, fullchain string, ca
return false return false
} }
} }
cert, err := x509.ParseCertificate(block.Bytes) cert, err := x509.ParseCertificate(block.Bytes)
if err != nil { if err != nil {
if fail == true { if fail == true {
...@@ -163,7 +166,6 @@ func checkCertificates(dnsname string, certificate string, fullchain string, ca ...@@ -163,7 +166,6 @@ func checkCertificates(dnsname string, certificate string, fullchain string, ca
} }
} }
return true return true
} }
// check if priv key matches the publick key // check if priv key matches the publick key
...@@ -202,6 +204,47 @@ func checkPrivkey(privkey string, pubcert string, opensslbinary string, fail boo ...@@ -202,6 +204,47 @@ func checkPrivkey(privkey string, pubcert string, opensslbinary string, fail boo
return true return true
} }
// check if priv key matches the publick key
/*
func checkPrivkey(privkey string, pubkey string, fail bool) bool {
// extract data from public key
pubkeyByte, errpubkey := ioutil.ReadFile(pubkey)
if errpubkey != nil {
fmt.Printf("[ERR] reading private key %v: %v\n", pubkey, errpubkey)
appExit(255)
}
block, _ := pem.Decode(pubkeyByte)
cert, _ = x509.ParseCertificate(block.Bytes)
rsaPublicKey := cert.PublicKey.(*rsa.PublicKey)
rsaPublicKeyString := fmt.Sprintf(rsaPublicKey.N.String())
// extract data from private key
privkeyByte, errprivkey := ioutil.ReadFile(privkey)
if errprivkey != nil {
fmt.Printf("[ERR] reading private key %v: %v\n", privkey, errprivkey)
appExit(255)
}
fmt.Printf("primo passaggio\n")
keyBlock, _ := pem.Decode(privkeyByte)
key, _ = x509.ParseCertificate(keyBlock.Bytes)
rsaPrivateKey := key.PublicKey.(*rsa.PrivateKey)
rsaPrivateKeyString := fmt.Sprintf(rsaPrivateKey.N.String())
fmt.Printf("primo passaggio")
if rsaPublicKeyString != rsaPrivateKeyString {
if fail == true {
fmt.Printf("[ERR] the private key %v does not match the the public key %v\n", privkey, pubkey)
appExit(255)
} else {
return false
}
}
return true
}
*/
// get redis key // get redis key
func GetRedisKey(redisurl string, redistoken string) string { func GetRedisKey(redisurl string, redistoken string) string {
client := &http.Client{} client := &http.Client{}
...@@ -427,6 +470,7 @@ Options: ...@@ -427,6 +470,7 @@ Options:
// check if there is a certificate installed and it is valid // check if there is a certificate installed and it is valid
existingCert := checkCertificates(CertName, certificateDestination, fullchainDestination, caDestination, keyDestination, Days, false) existingCert := checkCertificates(CertName, certificateDestination, fullchainDestination, caDestination, keyDestination, Days, false)
// existingKey := checkPrivkey(keyDestination, certificateDestination, false)
existingKey := checkPrivkey(keyDestination, certificateDestination, opensslBinary, false, silent) existingKey := checkPrivkey(keyDestination, certificateDestination, opensslBinary, false, silent)
if existingCert == true && existingKey == true { if existingCert == true && existingKey == true {
fmt.Printf("[INFO] the certificate is still valid\n") fmt.Printf("[INFO] the certificate is still valid\n")
...@@ -444,7 +488,8 @@ Options: ...@@ -444,7 +488,8 @@ Options:
WriteToFile(privKey, tmpKeyDestination, 0640) WriteToFile(privKey, tmpKeyDestination, 0640)
checkCertificates(CertName, tmpCertificateDestination, tmpFullchainDestination, tmpCaDestination, tmpKeyDestination, Days, true) checkCertificates(CertName, tmpCertificateDestination, tmpFullchainDestination, tmpCaDestination, tmpKeyDestination, Days, true)
checkPrivkey(keyDestination, tmpCertificateDestination, opensslBinary, false, silent) //checkPrivkey(tmpKeyDestination, tmpCertificateDestination, true)
checkPrivkey(tmpKeyDestination, tmpCertificateDestination, opensslBinary, true, silent)
// move certificates in place // move certificates in place
moveFile(tmpCertificateDestination, certificateDestination, GroupID, 0644, 0755) moveFile(tmpCertificateDestination, certificateDestination, GroupID, 0644, 0755)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment