[PD1] cryptoUtils start and protocol tweaks
This commit is contained in:
parent
cdaae8fb7e
commit
c57c093867
4 changed files with 128 additions and 80 deletions
|
@ -1,7 +1,49 @@
|
|||
package cryptoUtils
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"PD1/internal/client"
|
||||
"PD1/internal/protocol"
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"software.sslmate.com/src/go-pkcs12"
|
||||
)
|
||||
|
||||
func Print() {
|
||||
fmt.Println("crypto package")
|
||||
}
|
||||
|
||||
func getUserInfo(certFilename string) (
|
||||
rsa.PrivateKey,
|
||||
*x509.Certificate,
|
||||
[]*x509.Certificate,
|
||||
error) {
|
||||
var privKey rsa.PrivateKey
|
||||
|
||||
certFile, err := os.ReadFile(certFilename)
|
||||
if err != nil {
|
||||
log.Panicln("Provided certificate %v couldn't be opened", certFilename)
|
||||
return rsa.PrivateKey{}, nil, nil, err
|
||||
}
|
||||
|
||||
password := client.AskUserPassword()
|
||||
privKeyInterface, cert, caCerts, err := pkcs12.DecodeChain(certFile, password)
|
||||
privKey = privKeyInterface.(rsa.PrivateKey)
|
||||
if err != nil {
|
||||
log.Panicln("PKCS12 key store couldn't be decoded")
|
||||
return rsa.PrivateKey{}, nil, nil, err
|
||||
}
|
||||
if err := privKey.Validate(); err != nil {
|
||||
log.Panicln("Private key is not valid")
|
||||
return rsa.PrivateKey{}, nil, nil, err
|
||||
}
|
||||
return privKey, cert, caCerts, nil
|
||||
}
|
||||
|
||||
func encryptMessageContent(privKey rsa.PrivateKey, peerPubKey rsa.PublicKey, content []byte) []byte {
|
||||
// Digital envolope
|
||||
|
||||
func Print(){
|
||||
fmt.Println("crypto package")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue