1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-06 03:50:08 +02:00

Prepare key preparation.

This commit is contained in:
B. Petersen 2017-05-15 18:04:18 +02:00
parent f30a8f283b
commit 7099af4725
45 changed files with 157 additions and 184 deletions

View file

@ -54,8 +54,7 @@
<Add directory="libs/libetpan/include" />
<Add directory="libs/libetpan/include/libetpan" />
<Add directory="libs/sqlite" />
<Add directory="libs/netpgp/include" />
<Add directory="libs/netpgp/src/libmj" />
<Add directory="libs/netpgp" />
</Compiler>
<Unit filename="README.md" />
<Unit filename="libs/libetpan/src/data-types/base64.c">
@ -373,58 +372,58 @@
<Unit filename="libs/libetpan/src/main/libetpan_version.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/bufgap.c">
<Unit filename="libs/netpgp/bufgap.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/compress.c">
<Unit filename="libs/netpgp/compress.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/create.c">
<Unit filename="libs/netpgp/create.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/crypto.c">
<Unit filename="libs/netpgp/crypto.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/keyring.c">
<Unit filename="libs/netpgp/keyring.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/misc.c">
<Unit filename="libs/netpgp/misc.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/netpgp.c">
<Unit filename="libs/netpgp/mj.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/openssl_crypto.c">
<Unit filename="libs/netpgp/netpgp.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/packet-parse.c">
<Unit filename="libs/netpgp/openssl_crypto.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/packet-print.c">
<Unit filename="libs/netpgp/packet-parse.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/packet-show.c">
<Unit filename="libs/netpgp/packet-print.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/reader.c">
<Unit filename="libs/netpgp/packet-show.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/signature.c">
<Unit filename="libs/netpgp/reader.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/ssh2pgp.c">
<Unit filename="libs/netpgp/signature.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/symmetric.c">
<Unit filename="libs/netpgp/ssh2pgp.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/validate.c">
<Unit filename="libs/netpgp/symmetric.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/lib/writer.c">
<Unit filename="libs/netpgp/validate.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/netpgp/src/libmj/mj.c">
<Unit filename="libs/netpgp/writer.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="libs/sqlite/sqlite3.c">

View file

@ -28,7 +28,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@ -51,7 +51,7 @@
#endif
#include "bufgap.h"
#include "defs.h"
#include "defs-netpgp.h"
/* macros to get subscripts in buffer */
#define AFTSUB(bp, n) ((bp)->buf[(int)n])

View file

@ -49,7 +49,7 @@
/** \file
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -1,3 +1,8 @@
#ifndef __CONFIG_NETPGP_H__
#define __CONFIG_NETPGP_H__
/* src/lib/config.h. Generated from config.h.in by configure. */
/* src/lib/config.h.in. Generated from configure.ac by autoheader. */
@ -185,3 +190,6 @@
/* Define to the type of an unsigned integer type of width exactly 8 bits if
such a type exists and the standard includes do not define it. */
/* #undef uint8_t */
#endif /* __CONFIG_NETPGP_H__ */

View file

@ -49,7 +49,7 @@
/** \file
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -46,7 +46,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -49,7 +49,7 @@
/** \file
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -49,7 +49,7 @@
/** \file
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -33,7 +33,7 @@
#include <unistd.h>
#include "mj.h"
#include "defs.h"
#include "defs-netpgp.h"
/* save 'n' chars of 's' in malloc'd memory */
static char *

View file

@ -26,7 +26,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
@ -82,7 +82,7 @@ __RCSID("$NetBSD: netpgp.c,v 1.96 2012/02/22 06:58:54 agc Exp $");
#include "netpgpdefs.h"
#include "crypto.h"
#include "ssh2pgp.h"
#include "defs.h"
#include "defs-netpgp.h"
/* read any gpg config file */
static int

View file

@ -49,7 +49,7 @@
/** \file
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
@ -681,7 +681,7 @@ pgp_text_from_hash(pgp_hash_t *hash)
\return 1 if key generated successfully; otherwise 0
\note It is the caller's responsibility to call pgp_keydata_free(keydata)
*/
static unsigned
unsigned
rsa_generate_keypair(pgp_key_t *keydata,
const int numbits,
const unsigned long e,

View file

@ -50,7 +50,7 @@
/** \file
* \brief Parser for OpenPGP packets
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -50,7 +50,7 @@
/*
* ! \file \brief Standard API print functions
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -52,7 +52,7 @@
* Creates printable text strings from packet contents
*
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -54,6 +54,8 @@
#ifndef PACKET_H_
#define PACKET_H_
#include "config-netpgp.h"
#include <time.h>
#ifdef HAVE_OPENSSL_BN_H

View file

@ -46,7 +46,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -49,7 +49,7 @@
/** \file
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -1,95 +0,0 @@
/* $NetBSD: defs.h,v 1.1 2010/08/07 04:13:57 agc Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Alistair Crooks (agc@NetBSD.org)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DEFS_H_
#define DEFS_H_
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NEWARRAY(type,ptr,size,where,action) do { \
if ((ptr = calloc(sizeof(type), (unsigned)(size))) == NULL) { \
(void) fprintf(stderr, "%s: can't allocate %lu bytes\n", \
where, (unsigned long)(size * sizeof(type))); \
action; \
} \
} while( /* CONSTCOND */ 0)
#define RENEW(type, _ptr, _size, _newsize, where, action) do { \
type *_newptr; \
_newptr = realloc(_ptr, (size_t)(_newsize) * sizeof(type)); \
if (_newptr == NULL) { \
(void) fprintf(stderr, "%s: can't realloc %lu bytes\n", \
where, (unsigned long)((_newsize) * sizeof(type))); \
action; \
} else { \
(void) memset(&_newptr[_size], 0x0, \
(_newsize - _size) * sizeof(type)); \
_ptr = _newptr; \
_size = _newsize; \
} \
} while( /* CONSTCOND */ 0)
#define NEW(type, ptr, where, action) NEWARRAY(type, ptr, 1, where, action)
#define FREE(ptr) free(ptr)
#define ALLOC(type, v, size, c, init, incr, where, action) do { \
uint32_t _newsize = size; \
if (size == 0) { \
_newsize = init; \
NEWARRAY(type, v, _newsize, where ": new", action); \
} else if (c == size) { \
_newsize = size + incr; \
RENEW(type, v, size, _newsize, where ": renew", action); \
} \
size = _newsize; \
} while( /* CONSTCOND */ 0)
#define DEFINE_ARRAY(name, type) \
typedef struct name { \
uint32_t c; \
uint32_t size; \
type *v; \
} name
#endif /* !DEFS_H_ */

View file

@ -26,7 +26,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -46,7 +46,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -49,6 +49,8 @@
#ifndef TYPES_H_
#define TYPES_H_
#include "config-netpgp.h"
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif

View file

@ -46,7 +46,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -50,7 +50,7 @@
/** \file
* This file contains the base functions used by the writers.
*/
#include "config.h"
#include "config-netpgp.h"
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>

View file

@ -40,12 +40,26 @@
#include <string.h>
#include <netpgp.h>
/*from netpgp:*/
#include "packet-parse.h"
#include "errors.h"
#include "netpgpdefs.h"
#include "crypto.h"
#include "create.h"
#include "mrmailbox.h"
#include "mrkey.h"
#include "mre2ee.h"
#include "mre2ee_driver.h"
unsigned rsa_generate_keypair(pgp_key_t *keydata,
const int numbits,
const unsigned long e,
const char *hashalg,
const char *cipher);
void mre2ee_driver_init(mrmailbox_t* mailbox)
{
@ -57,33 +71,76 @@ void mre2ee_driver_exit(mrmailbox_t* mailbox)
}
/* original calls:
memset(&netpgp, 0, sizeof(netpgp_t));
netpgp_set_homedir(&netpgp, mailbox->m_blobdir, NULL, 1);
netpgp_init(&netpgp);
netpgp_generate_key(&netpgp, "foobar", 2048); <-- this calls rsa_generate_keypair()
netpgp_end(&netpgp);
*/
int mre2ee_driver_create_keypair(mrmailbox_t* mailbox, mrkey_t* public_key, mrkey_t* private_key)
{
netpgp_t netpgp;
int success = 0;
pgp_key_t* keydata = NULL;
pgp_memory_t* mem = NULL;
pgp_output_t* output = NULL;
mrkey_empty(public_key);
mrkey_empty(private_key);
if( mailbox==NULL || public_key==NULL || private_key==NULL ) {
return 0;
}
#if 1
{
netpgp_t netpgp;
memset(&netpgp, 0, sizeof(netpgp_t));
netpgp_set_homedir(&netpgp, mailbox->m_blobdir, NULL, 1);
netpgp_init(&netpgp);
netpgp_generate_key(&netpgp, "foobar", 2048); // <-- this calls rsa_generate_keypair()
netpgp_end(&netpgp);
}
#endif
if( mailbox==NULL || public_key==NULL || private_key==NULL ) {
goto cleanup;
}
if( (keydata=pgp_keydata_new())==NULL ) {
goto cleanup;
}
if (!rsa_generate_keypair(keydata, 2048/*bits*/, 65537UL/*e*/, NULL/*hash*/, NULL/*cipher*/) ) {
goto cleanup;
}
/* get public key */
if( (mem=pgp_memory_new())==NULL ) {
goto cleanup;
}
/* TODO: real implementation here! */
const char* dummy = "lkjslfjsdlfjsdlfjslkfjsflksjdflkjsdflksjdflksjflskjflsdjflsdjfsldkjfslkdjflskdjflkjslfjsdlfjsdlfjslkfjsflksjdflkjsdflksjdflksjflskjflsdjflsdjfsldkjfslkdjflskdjflkjslfjsdlfjsdlfjslkfjsflksjdflkjsdflksjdflksjflskjflsdjflsdjfsldkjfslkdjflskdjf";
mrkey_set_from_raw(public_key, (const unsigned char*)dummy, strlen(dummy), MR_PUBLIC);
mrkey_set_from_raw(private_key, (const unsigned char*)dummy, strlen(dummy), MR_PRIVATE);
pgp_build_pubkey(mem, &keydata->key.seckey.pubkey, 0);
if( mem->buf == NULL || mem->length <= 0 ) {
goto cleanup;
}
return 1;
mrkey_set_from_raw(public_key, (const unsigned char*)mem->buf, mem->length, MR_PUBLIC);
/* get private key */
pgp_memory_release(mem);
const char* passphrase = "passphrase";
output = pgp_output_new();
pgp_write_xfer_seckey(output, keydata, (const uint8_t*)passphrase, strlen(passphrase), 0);
if( mem->buf == NULL || mem->length <= 0 ) {
goto cleanup;
}
mrkey_set_from_raw(private_key, (const unsigned char*)mem->buf, mem->length, MR_PRIVATE);
cleanup:
if( mem ) { pgp_memory_free(mem); }
if( keydata ) { pgp_keydata_free(keydata); }
if( output ) { pgp_output_delete(output); }
return success;
}