/**
* xrdp : A Remote Desktop Protocol server .
*
* Copyright ( C ) Jay Sorg 2004 - 2014
*
* Licensed under the Apache License , Version 2 . 0 ( the " License " ) ;
* you may not use this file except in compliance with the License .
* You may obtain a copy of the License at
*
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an " AS IS " BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*
* rsa key generator for xrdp
*/
/*
references :
http : //www.securiteam.com/windowsntfocus/5EP010KG0G.html
*/
#if defined (HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include "os_calls.h"
#include "string_calls.h"
#include "ssl_calls.h"
#include "arch.h"
#include "list.h"
#include "file.h"
/* this is the signature size in bytes */
#define TSSK_KEY_LENGTH 64
/* default to 2048 bit key size, can set changed, set */
static int g_key_size_bits = 2048 ;
static tui8 g_exponent[4 ] =
{
0 x01, 0 x00, 0 x01, 0 x00
};
/* 4 bytes public exponent */
static tui8 g_ppk_e[4 ] =
{
0 x5B, 0 x7B, 0 x88, 0 xC0
};
/* 64 byte modulus */
static tui8 g_ppk_n[72 ] = /* 64 bytes + 8 bytes pad */
{
0 x3D, 0 x3A, 0 x5E, 0 xBD, 0 x72, 0 x43, 0 x3E, 0 xC9,
0 x4D, 0 xBB, 0 xC1, 0 x1E, 0 x4A, 0 xBA, 0 x5F, 0 xCB,
0 x3E, 0 x88, 0 x20, 0 x87, 0 xEF, 0 xF5, 0 xC1, 0 xE2,
0 xD7, 0 xB7, 0 x6B, 0 x9A, 0 xF2, 0 x52, 0 x45, 0 x95,
0 xCE, 0 x63, 0 x65, 0 x6B, 0 x58, 0 x3A, 0 xFE, 0 xEF,
0 x7C, 0 xE7, 0 xBF, 0 xFE, 0 x3D, 0 xF6, 0 x5C, 0 x7D,
0 x6C, 0 x5E, 0 x06, 0 x09, 0 x1A, 0 xF5, 0 x61, 0 xBB,
0 x20, 0 x93, 0 x09, 0 x5F, 0 x05, 0 x6D, 0 xEA, 0 x87,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00
};
/* 64 bytes private exponent */
static tui8 g_ppk_d[108 ] = /* 64 bytes + 44 bytes pad */
{
0 x87, 0 xA7, 0 x19, 0 x32, 0 xDA, 0 x11, 0 x87, 0 x55,
0 x58, 0 x00, 0 x16, 0 x16, 0 x25, 0 x65, 0 x68, 0 xF8,
0 x24, 0 x3E, 0 xE6, 0 xFA, 0 xE9, 0 x67, 0 x49, 0 x94,
0 xCF, 0 x92, 0 xCC, 0 x33, 0 x99, 0 xE8, 0 x08, 0 x60,
0 x17, 0 x9A, 0 x12, 0 x9F, 0 x24, 0 xDD, 0 xB1, 0 x24,
0 x99, 0 xC7, 0 x3A, 0 xB8, 0 x0A, 0 x7B, 0 x0D, 0 xDD,
0 x35, 0 x07, 0 x79, 0 x17, 0 x0B, 0 x51, 0 x9B, 0 xB3,
0 xC7, 0 x10, 0 x01, 0 x13, 0 xE7, 0 x3F, 0 xF3, 0 x5F,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00
};
/* 512 bit proprietary certificate
dwVersion 0 4 bytes always 0 x00000001
dwSigAlgId 4 4 bytes always 0 x00000001
dwKeyAlgId 8 4 bytes always 0 x00000001
wPublicKeyBlobType 12 2 bytes always 0 x0006
wPublicKeyBlobLen 14 2 bytes 0 x005C 92 bytes
magic 16 4 bytes always 0 x31415352
keylen 20 4 bytes 0 x0048 72 bytes
bitlen 24 4 bytes 0 x0200 512 bits
datalen 28 4 bytes 0 x003F 63 bytes
pubExp 32 4 bytes 0 x00010001
modulus 36 72 bytes
wSignatureBlobType 108 2 bytes always 0 x0008
wSignatureBlobLen 110 2 bytes 0 x0048 72 bytes
SignatureBlob 112 72 bytes */
static tui8 g_testkey512[184 ] = /* 512 bit test key */
{
0 x01, 0 x00, 0 x00, 0 x00, 0 x01, 0 x00, 0 x00, 0 x00, /* 0 */
0 x01, 0 x00, 0 x00, 0 x00, 0 x06, 0 x00, 0 x5c, 0 x00,
0 x52, 0 x53, 0 x41, 0 x31, 0 x48, 0 x00, 0 x00, 0 x00,
0 x00, 0 x02, 0 x00, 0 x00, 0 x3f, 0 x00, 0 x00, 0 x00,
0 x01, 0 x00, 0 x01, 0 x00, 0 x79, 0 x6f, 0 xb4, 0 xdf, /* 32 */
0 xa6, 0 x95, 0 xb9, 0 xa9, 0 x61, 0 xe3, 0 xc4, 0 x5e,
0 xff, 0 x6b, 0 xd8, 0 x81, 0 x8a, 0 x12, 0 x4a, 0 x93,
0 x42, 0 x97, 0 x18, 0 x93, 0 xac, 0 xd1, 0 x3a, 0 x38,
0 x3c, 0 x68, 0 x50, 0 x19, 0 x31, 0 xb6, 0 x84, 0 x51, /* 64 */
0 x79, 0 xfb, 0 x1c, 0 xe7, 0 xe3, 0 x99, 0 x20, 0 xc7,
0 x84, 0 xdf, 0 xd1, 0 xaa, 0 xb5, 0 x15, 0 xef, 0 x47,
0 x7e, 0 xfc, 0 x88, 0 xeb, 0 x29, 0 xc3, 0 x27, 0 x5a,
0 x35, 0 xf8, 0 xfd, 0 xaa, 0 x00, 0 x00, 0 x00, 0 x00, /* 96 */
0 x00, 0 x00, 0 x00, 0 x00, 0 x08, 0 x00, 0 x48, 0 x00,
0 x32, 0 x3b, 0 xde, 0 x6f, 0 x18, 0 x97, 0 x1e, 0 xc3,
0 x6b, 0 x2b, 0 x2d, 0 xe4, 0 xfc, 0 x2d, 0 xa2, 0 x8e,
0 x32, 0 x3c, 0 xf3, 0 x1b, 0 x24, 0 x90, 0 x57, 0 x4d, /* 128 */
0 x8e, 0 xe4, 0 x69, 0 xfc, 0 x16, 0 x8d, 0 x41, 0 x92,
0 x78, 0 xc7, 0 x9c, 0 xb4, 0 x26, 0 xff, 0 xe8, 0 x3e,
0 xa1, 0 x8a, 0 xf5, 0 x57, 0 xc0, 0 x7f, 0 x3e, 0 x21,
0 x17, 0 x32, 0 x30, 0 x6f, 0 x79, 0 xe1, 0 x36, 0 xcd, /* 160 */
0 xb6, 0 x8e, 0 xbe, 0 x57, 0 x57, 0 xd2, 0 xa9, 0 x36,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00
};
/* 2048 bit proprietary certificate
dwVersion 0 4 bytes always 0 x00000001
dwSigAlgId 4 4 bytes always 0 x00000001
dwKeyAlgId 8 4 bytes always 0 x00000001
wPublicKeyBlobType 12 2 bytes always 0 x0006
wPublicKeyBlobLen 14 2 bytes 0 x011C 284 bytes
magic 16 4 bytes always 0 x31415352
keylen 20 4 bytes 0 x0108 264 bytes
bitlen 24 4 bytes 0 x0800 2048 bits
datalen 28 4 bytes 0 x00FF 255 bytes
pubExp 32 4 bytes 0 x00010001
modulus 36 264 bytes
wSignatureBlobType 300 2 bytes always 0 x0008
wSignatureBlobLen 302 2 bytes 0 x0048 72 bytes
SignatureBlob 304 72 bytes */
static tui8 g_testkey2048[376 ] = /* 2048 bit test key */
{
0 x01, 0 x00, 0 x00, 0 x00, 0 x01, 0 x00, 0 x00, 0 x00, /* 0 */
0 x01, 0 x00, 0 x00, 0 x00, 0 x06, 0 x00, 0 x1c, 0 x01,
0 x52, 0 x53, 0 x41, 0 x31, 0 x08, 0 x01, 0 x00, 0 x00,
0 x00, 0 x08, 0 x00, 0 x00, 0 xff, 0 x00, 0 x00, 0 x00,
0 x01, 0 x00, 0 x01, 0 x00, 0 x13, 0 x77, 0 x6d, 0 xd8, /* 32 */
0 x7b, 0 x6e, 0 x6f, 0 x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 x65, 0 x88, 0 xfc,
0 x35, 0 x0a, 0 x04, 0 xa0, 0 xda, 0 xc1, 0 xab, 0 xbf, /* 352 */
0 xcd, 0 xf1, 0 x7e, 0 x71, 0 x7b, 0 xf8, 0 x4a, 0 x78,
0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00, 0 x00
};
/*****************************************************************************/
static int
out_params(void )
{
g_writeln("%s" , "" );
g_writeln("xrdp rsa key gen utility examples" );
g_writeln(" xrdp-keygen xrdp ['path and file name' | auto] [512 or 2048]" );
g_writeln(" xrdp-keygen test" );
g_writeln("%s" , "" );
return 0 ;
}
/*****************************************************************************/
/* this is the special key signing algorithm */
static int
sign_key(const char *e_data, int e_len, const char *n_data, int n_len,
char *sign_data, int sign_len)
{
char *key;
char *md5_final;
void *md5;
if ((e_len != 4 ) || ((n_len != 64 ) && (n_len != 256 )) || (sign_len != 64 ))
{
return 1 ;
}
if (n_len == 64 )
{
key = (char *)g_malloc(184 , 0 );
md5_final = (char *)g_malloc(64 , 0 );
md5 = ssl_md5_info_create();
/* copy the test key */
g_memcpy(key, g_testkey512, 184 );
/* replace e and n */
g_memcpy(key + 32 , e_data, e_len);
g_memcpy(key + 36 , n_data, n_len);
ssl_md5_clear(md5);
/* the first 108 bytes */
ssl_md5_transform(md5, key, 108 );
/* set the whole thing with 0xff */
g_memset(md5_final, 0 xff, 64 );
/* digest 16 bytes */
ssl_md5_complete(md5, md5_final);
/* set non 0xff array items */
md5_final[16 ] = 0 ;
md5_final[62 ] = 1 ;
md5_final[63 ] = 0 ;
/* encrypt */
ssl_mod_exp(sign_data, sign_len, md5_final, 64 , (char *)g_ppk_n, 64 ,
(char *)g_ppk_d, 64 );
/* cleanup */
ssl_md5_info_delete(md5);
g_free(key);
g_free(md5_final);
}
else if (n_len == 256 )
{
key = (char *)g_malloc(376 , 0 );
md5_final = (char *)g_malloc(64 , 0 );
md5 = ssl_md5_info_create();
/* copy the test key */
g_memcpy(key, g_testkey2048, 376 );
/* replace e and n */
g_memcpy(key + 32 , e_data, e_len);
g_memcpy(key + 36 , n_data, n_len);
ssl_md5_clear(md5);
/* the first 300 bytes */
ssl_md5_transform(md5, key, 300 );
/* set the whole thing with 0xff */
g_memset(md5_final, 0 xff, 64 );
/* digest 16 bytes */
ssl_md5_complete(md5, md5_final);
/* set non 0xff array items */
md5_final[16 ] = 0 ;
md5_final[62 ] = 1 ;
md5_final[63 ] = 0 ;
/* encrypt */
ssl_mod_exp(sign_data, sign_len, md5_final, 64 , (char *)g_ppk_n, 64 ,
(char *)g_ppk_d, 64 );
/* cleanup */
ssl_md5_info_delete(md5);
g_free(key);
g_free(md5_final);
}
return 0 ;
}
/*****************************************************************************/
static int
write_out_line(int fd, const char *name, const char *data, int len)
{
int max;
int error;
int index;
int data_item;
int buf_pos;
char *buf;
char *text;
text = (char *)g_malloc(256 , 0 );
max = len;
max = max * 10 ;
buf_pos = g_strlen(name);
max = max + buf_pos + 16 ;
buf = (char *)g_malloc(max, 0 );
g_strncpy(buf, name, max - 1 );
buf[buf_pos] = '=' ;
buf_pos++;
for (index = 0 ; index < len; index++)
{
data_item = (tui8)(data[index]);
g_snprintf(text, 255 , "0x%2.2x" , data_item);
if (index != 0 )
{
buf[buf_pos] = ',' ;
buf_pos++;
}
buf[buf_pos] = text[0 ];
buf_pos++;
buf[buf_pos] = text[1 ];
buf_pos++;
buf[buf_pos] = text[2 ];
buf_pos++;
buf[buf_pos] = text[3 ];
buf_pos++;
}
buf[buf_pos] = '\n' ;
buf_pos++;
buf[buf_pos] = 0 ;
error = g_file_write(fd, buf, buf_pos) == -1 ;
g_free(buf);
g_free(text);
return error;
}
/*****************************************************************************/
static int
save_all(const char *e_data, int e_len, const char *n_data, int n_len,
const char *d_data, int d_len, const char *sign_data, int sign_len,
const char *path_and_file_name)
{
int fd;
char filename[256 ];
if (path_and_file_name == 0 )
{
g_strncpy(filename, "rsakeys.ini" , 255 );
}
else
{
g_strncpy(filename, path_and_file_name, 255 );
}
g_writeln("saving to %s" , filename);
g_writeln("%s" , "" );
if (g_file_exist(filename))
{
if (g_file_delete(filename) == 0 )
{
g_writeln("problem deleting %s, maybe no rights" , filename);
return 1 ;
}
}
fd = g_file_open_rw(filename);
if (fd != -1 )
{
if (g_file_write(fd, "[keys]\n" , 7 ) == -1 )
{
g_writeln("problem writing to %s, maybe no rights" , filename);
g_file_close(fd);
return 1 ;
}
write_out_line(fd, "pub_exp" , e_data, e_len);
write_out_line(fd, "pub_mod" , n_data, n_len);
write_out_line(fd, "pub_sig" , sign_data, sign_len);
write_out_line(fd, "pri_exp" , d_data, d_len);
}
else
{
g_writeln("problem opening %s, maybe no rights" , filename);
return 1 ;
}
g_file_close(fd);
return 0 ;
}
/*****************************************************************************/
static int
key_gen(const char *path_and_file_name)
{
char *e_data;
char *n_data;
char *d_data;
char *sign_data;
int e_len;
int n_len;
int d_len;
int sign_len;
int error;
e_data = (char *)g_exponent;
n_data = (char *)g_malloc(256 , 0 );
d_data = (char *)g_malloc(256 , 0 );
sign_data = (char *)g_malloc(64 , 0 );
e_len = 4 ;
n_len = g_key_size_bits / 8 ;
d_len = n_len;
sign_len = 64 ;
error = 0 ;
g_writeln("%s" , "" );
g_writeln("Generating %d bit rsa key..." , g_key_size_bits);
g_writeln("%s" , "" );
if (error == 0 )
{
error = ssl_gen_key_xrdp1(g_key_size_bits, e_data, e_len, n_data, n_len,
d_data, d_len);
if (error != 0 )
{
g_writeln("error %d in key_gen, ssl_gen_key_xrdp1" , error);
}
}
if (error == 0 )
{
g_writeln("ssl_gen_key_xrdp1 ok" );
g_writeln("%s" , "" );
error = sign_key(e_data, e_len, n_data, n_len, sign_data, sign_len);
if (error != 0 )
{
g_writeln("error %d in key_gen, sign_key" , error);
}
}
if (error == 0 )
{
error = save_all(e_data, e_len, n_data, n_len, d_data, d_len,
sign_data, sign_len, path_and_file_name);
if (error != 0 )
{
g_writeln("error %d in key_gen, save_all" , error);
}
}
g_free(n_data);
g_free(d_data);
g_free(sign_data);
return error;
}
/*****************************************************************************/
static int
key_gen_auto(void )
{
return key_gen(XRDP_CFG_PATH "/rsakeys.ini" );
}
/*****************************************************************************/
static int
key_test512(void )
{
char *md5_final;
char *sig;
void *md5;
md5_final = (char *)g_malloc(64 , 0 );
sig = (char *)g_malloc(64 , 0 );
md5 = ssl_md5_info_create();
g_writeln("original key is:" );
g_hexdump((char *)g_testkey512, 184 );
g_writeln("original exponent is:" );
g_hexdump((char *)g_testkey512 + 32 , 4 );
g_writeln("original modulus is:" );
g_hexdump((char *)g_testkey512 + 36 , 64 );
g_writeln("original signature is:" );
g_hexdump((char *)g_testkey512 + 112 , 64 );
ssl_md5_clear(md5);
ssl_md5_transform(md5, (char *)g_testkey512, 108 );
g_memset(md5_final, 0 xff, 64 );
ssl_md5_complete(md5, md5_final);
g_writeln("md5 hash of first 108 bytes of this key is:" );
g_hexdump(md5_final, 16 );
md5_final[16 ] = 0 ;
md5_final[62 ] = 1 ;
md5_final[63 ] = 0 ;
ssl_mod_exp(sig, 64 , md5_final, 64 , (char *)g_ppk_n, 64 , (char *)g_ppk_d, 64 );
g_writeln("produced signature(this should match original "
"signature above) is:" );
g_hexdump(sig, 64 );
g_memset(md5_final, 0 , 64 );
ssl_mod_exp(md5_final, 64 , (char *)g_testkey512 + 112 , 64 , (char *)g_ppk_n, 64 ,
(char *)g_ppk_e, 4 );
g_writeln("decrypted hash of first 108 bytes of this key is:" );
g_hexdump(md5_final, 64 );
ssl_md5_info_delete(md5);
g_free(md5_final);
g_free(sig);
return 0 ;
}
/*****************************************************************************/
static int
key_test2048(void )
{
char *md5_final;
char *sig;
void *md5;
md5_final = (char *)g_malloc(64 , 0 );
sig = (char *)g_malloc(64 , 0 );
md5 = ssl_md5_info_create();
g_writeln("original key is:" );
g_hexdump((char *)g_testkey2048, 376 );
g_writeln("original exponent is:" );
g_hexdump((char *)g_testkey2048 + 32 , 4 );
g_writeln("original modulus is:" );
g_hexdump((char *)g_testkey2048 + 36 , 256 );
g_writeln("original signature is:" );
g_hexdump((char *)g_testkey2048 + 304 , 64 );
ssl_md5_clear(md5);
ssl_md5_transform(md5, (char *)g_testkey2048, 300 );
g_memset(md5_final, 0 xff, 64 );
ssl_md5_complete(md5, md5_final);
g_writeln("md5 hash of first 300 bytes of this key is:" );
g_hexdump(md5_final, 16 );
md5_final[16 ] = 0 ;
md5_final[62 ] = 1 ;
md5_final[63 ] = 0 ;
ssl_mod_exp(sig, 64 , md5_final, 64 , (char *)g_ppk_n, 64 , (char *)g_ppk_d, 64 );
g_writeln("produced signature(this should match original "
"signature above) is:" );
g_hexdump(sig, 64 );
g_memset(md5_final, 0 , 64 );
ssl_mod_exp(md5_final, 64 , (char *)g_testkey2048 + 304 , 64 , (char *)g_ppk_n, 64 ,
(char *)g_ppk_e, 4 );
g_writeln("decrypted hash of first 108 bytes of this key is:" );
g_hexdump(md5_final, 64 );
ssl_md5_info_delete(md5);
g_free(md5_final);
g_free(sig);
return 0 ;
}
/*****************************************************************************/
int
main(int argc, char **argv)
{
if (argc > 1 )
{
if (g_strcasecmp(argv[1 ], "xrdp" ) == 0 )
{
if (argc > 2 )
{
if (argc > 3 )
{
g_key_size_bits = g_atoi(argv[3 ]);
if ((g_key_size_bits != 512 ) && (g_key_size_bits != 2048 ))
{
out_params();
return 0 ;
}
}
if (g_strcasecmp(argv[2 ], "auto" ) == 0 )
{
if (g_getuid() != 0 )
{
g_writeln("must run as root" );
return 0 ;
}
return key_gen_auto();
}
else
{
return key_gen(argv[2 ]);
}
}
else
{
return key_gen(0 );
}
}
else if (g_strcasecmp(argv[1 ], "test" ) == 0 )
{
g_writeln("%s" , "" );
g_writeln("testing 512 bit key" );
key_test512();
g_writeln("%s" , "" );
g_writeln("testing 2048 bit key" );
key_test2048();
return 0 ;
}
}
out_params();
return 0 ;
}
Messung V0.5 in Prozent C=93 H=93 G=92
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-07-10)
¤
*© Formatika GbR, Deutschland