libp2p / go-openssl Goto Github PK
View Code? Open in Web Editor NEWThis project forked from spacemonkeygo/openssl
UNMAINTAINED - OpenSSL bindings for Go
Home Page: http://godoc.org/github.com/spacemonkeygo/openssl
License: Apache License 2.0
This project forked from spacemonkeygo/openssl
UNMAINTAINED - OpenSSL bindings for Go
Home Page: http://godoc.org/github.com/spacemonkeygo/openssl
License: Apache License 2.0
I was trying to run go-openssl under Windows and got in trouble with the server certificate and private key files to be loaded by the openssl.ListenAndServeTLS()
function. Instead of starting up normally, the server process ended immediately with the following error: No PEM certificate found in 'server.crt'
. At the end, it turned out that the only problem were the CRLF line endings in the server certificate and private key files. After having changed then to LF, everything worked like a charm.
Nevertheless, this is a non-obvious pitfall making go-openssl somewhat difficult to use under Windows. It therefore would be preferable to make it happen that PEM files used regardless whether their line ending is LF or CRLF. This seems also to be a common practice for most other TLS/SSL applications and libraries.
Now that libp2p/go-libp2p#1953 has been merged, we should archive this repo and lessen maintenance overhead.
I want to pass this code in c++ to golang
`#include
#include <openssl/engine.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/crypto.h>
usando namespace std;
int main()
{
OpenSSL_add_all_algorithms();
ENGINE_load_dynamic();
// Configura o mecanismo OpenSSL
ENGINE* engine = ENGINE_by_id("dynamic");
string enginePath = "/usr/local/lib/engines/pkcs11.so";
string modulePath = "/usr/local/lib/opensc-pkcs11.so";
ENGINE_ctrl_cmd_string(engine,"SO_PATH", enginePath.c_str(), 0);
ENGINE_ctrl_cmd_string(engine,"LIST_ADD","1", 0);
ENGINE_ctrl_cmd_string(engine,"CARREGAR", NULO, 0);
ENGINE_ctrl_cmd_string(engine,"MODULE_PATH", modulePath.c_str(), 0);
string pin ="123456";
ENGINE_ctrl_cmd_string(engine,"PIN", pin.c_str(), 0);
ENGINE_ctrl_cmd_string(engine,"VERBOSE", NULL , 0);
ENGINE_init(engine);
ENGINE_set_default(engine, ENGINE_METHOD_ALL);
string keyName ="id_9352";
EVP_PKEY *evp = ENGINE_load_private_key(engine, keyName.c_str(), NULL, NULL);
// Lê o arquivo criptografado
long unsigned int comprimento = 128;
caractere unsigned buf[comprimento];
FILE* f = fopen("encrypted.bin","r");
fread(buf, 1, comprimento, f);
fclose(f);
// Tenta descriptografar
unsigned char output[comprimento];
unsigned char* p = output;
RSA *rsa = EVP_PKEY_get1_RSA(evp);
int outputLen = RSA_private_decrypt(comprimento, buf, p, rsa, RSA_PKCS1_PADDING);
if (outputLen == -1) {
long err = ERR_get_error();
cout < <"Erro ao descriptografar:" << ERR_error_string(err, NULL) << endl;
return 1;
}
cout << output << endl;
return 0;
}`
Me and I started to do it but stop here
`
type Engine struct {
e *C.ENGINE
}
func EngineById(name string) (*Engine, error) {
C.init()
cname := C.CString(name)
log.Println(name)
defer C.free(unsafe.Pointer(cname))
e := &Engine{
e: C.ENGINE_by_id(cname),
}
if e.e == nil {
return nil, fmt.Errorf("engine %s missing", name)
}
cParamSoPath := C.CString("SO_PATH")
defer C.free(unsafe.Pointer(cParamSoPath))
cValueSoPath := C.CString("/usr/lib/i386-linux-gnu/engines-1.1/pkcs11.so")
defer C.free(unsafe.Pointer(cValueSoPath))
cParamListAdd := C.CString("LIST_ADD")
defer C.free(unsafe.Pointer(cParamListAdd))
cValueListAdd := C.CString("1")
defer C.free(unsafe.Pointer(cValueListAdd))
cParamLoad := C.CString("LOAD")
defer C.free(unsafe.Pointer(cParamLoad))
cParamModulePath := C.CString("MODULE_PATH")
defer C.free(unsafe.Pointer(cParamModulePath))
cValueModulePath := C.CString("/home/procondutor/libaetpkss.so.3.0.3930")
defer C.free(unsafe.Pointer(cValueModulePath))
cParamPin := C.CString("PIN")
defer C.free(unsafe.Pointer(cParamPin))
cValuePin := C.CString("2903")
defer C.free(unsafe.Pointer(cValuePin))
C.ENGINE_ctrl_cmd_string(e.e, cParamSoPath, cValueSoPath, 0);
C.ENGINE_ctrl_cmd_string(e.e, cParamListAdd, cValueListAdd, 0);
C.ENGINE_ctrl_cmd_string(e.e, cParamLoad, nil, 0);
C.ENGINE_ctrl_cmd_string(e.e, cParamModulePath, cValueModulePath, 0);
C.ENGINE_ctrl_cmd_string(e.e, cParamPin, cValuePin, 0);
if C.ENGINE_init(e.e) == 0 {
C.ENGINE_free(e.e)
return nil, fmt.Errorf("engine %s not initialized", name)
}
C.ENGINE_set_default(e.e, C.ENGINE_METHOD_ALL);
string keyName := "pkcs11:model=19C43A06010D0000;manufacturer=A.E.T.%20Europe%20B.V.;serial=022A00100020FA04;token=TOKEN;id=%19%00%00%00;object=Procondutor;type=private"
cKeyName := C.CString(keyName)
defer C.free(unsafe.Pointer(cKeyName))
evp := C.ENGINE_load_private_key(e.e, cKeyName, nil, nil)
runtime.SetFinalizer(e, func(e *Engine) {
C.ENGINE_finish(e.e)
C.ENGINE_free(e.e)
})
}
`
can someone help me complete it?
In the process of testing libp2p hydra-boosters, I compiled them on Ubuntu 22, linking against the master branch of this library (needed OpenSSLv3 support, otherwise cannot build).
Running with this resulted in a significant amount of handshake error messages and panics (SIGSEGV - segmentation faults). I had to run without openssl support in the end.
Therefore, chances are that this library is broken to certain extent and cannot be used with go-libp2p, at least in the current state from master, even though I can't say how.
TLS 1.3 is the minimum protocol version for the libp2p TLS handshake: https://github.com/libp2p/specs/blob/master/tls/tls.md#handshake-protocol.
Lines 22 to 25 in 6d00a81
Allows for whitespace and dashes beyond what is allowed in the spec https://tools.ietf.org/html/rfc7468. We should clean this up.
Is there a way to convert CRT/DER formatted certificates to normal PEM ones?
Just like you would do with openssl:
openssl x509 -inform der -in input.cer -out output.pem
Thanks in advance!
https://github.com/libp2p/go-openssl/runs/7894753574?check_suite_focus=true
=== RUN TestOpenSSLSimple
ssl_test.go:196: read tcp 127.0.0.1:52366->127.0.0.1:52367: wsarecv: An established connection was aborted by the software in your host machine.
--- FAIL: TestOpenSSLSimple (0.06s)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.