Coder Social home page Coder Social logo

libp2p / go-openssl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spacemonkeygo/openssl

15.0 2.0 20.0 341 KB

UNMAINTAINED - OpenSSL bindings for Go

Home Page: http://godoc.org/github.com/spacemonkeygo/openssl

License: Apache License 2.0

Go 83.92% C 16.08%

go-openssl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-openssl's Issues

Enable PEM files with CRLF line endings to be used

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.

fix GoDoc link in "About" section

Looks like I don't have permissions to edit this. Whoever owns this repository should probably change the GoDoc link in the "About" section.

image

Parse C++ to Golang

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?

Handshake errors and panics when using master

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.

Convert CRT/DER to PEM

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.