cordova-plugin-mserviceinterface-2.0 1.0.21 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -28
- package/plugin.xml +153 -153
- package/src/android/CallbackProgressDialog.java +53 -53
- package/src/android/FileProvider.java +7 -7
- package/src/android/backgroundNotification.java +120 -120
- package/src/android/doubleogradle.gradle +5 -5
- package/src/android/mInterface.java +2087 -2066
- package/src/android/mInterfaceReceiver.java +59 -59
- package/src/android/mInterfaceService.java +749 -749
- package/src/android/mInterfaceUtil.java +1686 -1688
- package/src/android/res/xml/network_security_config.xml +8 -8
- package/src/android/res/xml/opener_paths.xml +16 -16
- package/src/ios/InternetConnection.h +64 -64
- package/src/ios/InternetConnection.m +242 -242
- package/src/ios/SSZipArchive.h +146 -146
- package/src/ios/SSZipArchive.m +1180 -1180
- package/src/ios/SSZipCommon.h +66 -66
- package/src/ios/UICKeyChainStore.h +64 -64
- package/src/ios/UICKeyChainStore.m +434 -434
- package/src/ios/XMLConverter.h +61 -61
- package/src/ios/XMLConverter.m +243 -243
- package/src/ios/ZipArchive.h +19 -19
- package/src/ios/aes/aes.h +270 -270
- package/src/ios/aes/aes_ni.c +687 -687
- package/src/ios/aes/aes_ni.h +59 -59
- package/src/ios/aes/aescrypt.c +301 -301
- package/src/ios/aes/aeskey.c +554 -554
- package/src/ios/aes/aesopt.h +776 -776
- package/src/ios/aes/aestab.c +418 -418
- package/src/ios/aes/aestab.h +173 -173
- package/src/ios/aes/brg_endian.h +127 -127
- package/src/ios/aes/brg_types.h +191 -191
- package/src/ios/aes/fileenc.c +145 -145
- package/src/ios/aes/fileenc.h +121 -121
- package/src/ios/aes/hmac.c +209 -209
- package/src/ios/aes/hmac.h +119 -119
- package/src/ios/aes/prng.c +155 -155
- package/src/ios/aes/prng.h +82 -82
- package/src/ios/aes/pwd2key.c +181 -181
- package/src/ios/aes/pwd2key.h +45 -45
- package/src/ios/aes/sha1.c +283 -283
- package/src/ios/aes/sha1.h +72 -72
- package/src/ios/mInterface.h +2 -0
- package/src/ios/mInterface.m +18 -1
- package/src/ios/minizip/crypt.c +146 -146
- package/src/ios/minizip/crypt.h +66 -66
- package/src/ios/minizip/ioapi.c +353 -353
- package/src/ios/minizip/ioapi.h +154 -154
- package/src/ios/minizip/ioapi_buf.c +452 -452
- package/src/ios/minizip/ioapi_buf.h +52 -52
- package/src/ios/minizip/ioapi_mem.c +167 -167
- package/src/ios/minizip/ioapi_mem.h +52 -52
- package/src/ios/minizip/minishared.c +292 -292
- package/src/ios/minizip/minishared.h +50 -50
- package/src/ios/minizip/unzip.c +2007 -2007
- package/src/ios/minizip/unzip.h +254 -254
- package/src/ios/minizip/zip.c +2007 -2007
- package/src/ios/minizip/zip.h +215 -215
- package/www/mInterface.js +3 -3
package/src/ios/aes/sha1.h
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
/*
|
|
2
|
-
---------------------------------------------------------------------------
|
|
3
|
-
Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
|
|
4
|
-
|
|
5
|
-
The redistribution and use of this software (with or without changes)
|
|
6
|
-
is allowed without the payment of fees or royalties provided that:
|
|
7
|
-
|
|
8
|
-
source code distributions include the above copyright notice, this
|
|
9
|
-
list of conditions and the following disclaimer;
|
|
10
|
-
|
|
11
|
-
binary distributions include the above copyright notice, this list
|
|
12
|
-
of conditions and the following disclaimer in their documentation.
|
|
13
|
-
|
|
14
|
-
This software is provided 'as is' with no explicit or implied warranties
|
|
15
|
-
in respect of its operation, including, but not limited to, correctness
|
|
16
|
-
and fitness for purpose.
|
|
17
|
-
---------------------------------------------------------------------------
|
|
18
|
-
Issue Date: 20/12/2007
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
#ifndef _SHA1_H
|
|
22
|
-
#define _SHA1_H
|
|
23
|
-
|
|
24
|
-
#define SHA_1
|
|
25
|
-
|
|
26
|
-
/* define for bit or byte oriented SHA */
|
|
27
|
-
#if 1
|
|
28
|
-
# define SHA1_BITS 0 /* byte oriented */
|
|
29
|
-
#else
|
|
30
|
-
# define SHA1_BITS 1 /* bit oriented */
|
|
31
|
-
#endif
|
|
32
|
-
|
|
33
|
-
#include <stdlib.h>
|
|
34
|
-
#include "brg_types.h"
|
|
35
|
-
|
|
36
|
-
#define SHA1_BLOCK_SIZE 64
|
|
37
|
-
#define SHA1_DIGEST_SIZE 20
|
|
38
|
-
|
|
39
|
-
#if defined(__cplusplus)
|
|
40
|
-
extern "C"
|
|
41
|
-
{
|
|
42
|
-
#endif
|
|
43
|
-
|
|
44
|
-
/* type to hold the SHA256 context */
|
|
45
|
-
|
|
46
|
-
typedef struct
|
|
47
|
-
{ uint32_t count[2];
|
|
48
|
-
uint32_t hash[SHA1_DIGEST_SIZE >> 2];
|
|
49
|
-
uint32_t wbuf[SHA1_BLOCK_SIZE >> 2];
|
|
50
|
-
} sha1_ctx;
|
|
51
|
-
|
|
52
|
-
/* Note that these prototypes are the same for both bit and */
|
|
53
|
-
/* byte oriented implementations. However the length fields */
|
|
54
|
-
/* are in bytes or bits as appropriate for the version used */
|
|
55
|
-
/* and bit sequences are input as arrays of bytes in which */
|
|
56
|
-
/* bit sequences run from the most to the least significant */
|
|
57
|
-
/* end of each byte. The value 'len' in sha1_hash for the */
|
|
58
|
-
/* byte oriented version of SHA1 is limited to 2^29 bytes, */
|
|
59
|
-
/* but multiple calls will handle longer data blocks. */
|
|
60
|
-
|
|
61
|
-
VOID_RETURN sha1_compile(sha1_ctx ctx[1]);
|
|
62
|
-
|
|
63
|
-
VOID_RETURN sha1_begin(sha1_ctx ctx[1]);
|
|
64
|
-
VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]);
|
|
65
|
-
VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]);
|
|
66
|
-
VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len);
|
|
67
|
-
|
|
68
|
-
#if defined(__cplusplus)
|
|
69
|
-
}
|
|
70
|
-
#endif
|
|
71
|
-
|
|
72
|
-
#endif
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------------------------------------------------
|
|
3
|
+
Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved.
|
|
4
|
+
|
|
5
|
+
The redistribution and use of this software (with or without changes)
|
|
6
|
+
is allowed without the payment of fees or royalties provided that:
|
|
7
|
+
|
|
8
|
+
source code distributions include the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer;
|
|
10
|
+
|
|
11
|
+
binary distributions include the above copyright notice, this list
|
|
12
|
+
of conditions and the following disclaimer in their documentation.
|
|
13
|
+
|
|
14
|
+
This software is provided 'as is' with no explicit or implied warranties
|
|
15
|
+
in respect of its operation, including, but not limited to, correctness
|
|
16
|
+
and fitness for purpose.
|
|
17
|
+
---------------------------------------------------------------------------
|
|
18
|
+
Issue Date: 20/12/2007
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#ifndef _SHA1_H
|
|
22
|
+
#define _SHA1_H
|
|
23
|
+
|
|
24
|
+
#define SHA_1
|
|
25
|
+
|
|
26
|
+
/* define for bit or byte oriented SHA */
|
|
27
|
+
#if 1
|
|
28
|
+
# define SHA1_BITS 0 /* byte oriented */
|
|
29
|
+
#else
|
|
30
|
+
# define SHA1_BITS 1 /* bit oriented */
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#include <stdlib.h>
|
|
34
|
+
#include "brg_types.h"
|
|
35
|
+
|
|
36
|
+
#define SHA1_BLOCK_SIZE 64
|
|
37
|
+
#define SHA1_DIGEST_SIZE 20
|
|
38
|
+
|
|
39
|
+
#if defined(__cplusplus)
|
|
40
|
+
extern "C"
|
|
41
|
+
{
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
/* type to hold the SHA256 context */
|
|
45
|
+
|
|
46
|
+
typedef struct
|
|
47
|
+
{ uint32_t count[2];
|
|
48
|
+
uint32_t hash[SHA1_DIGEST_SIZE >> 2];
|
|
49
|
+
uint32_t wbuf[SHA1_BLOCK_SIZE >> 2];
|
|
50
|
+
} sha1_ctx;
|
|
51
|
+
|
|
52
|
+
/* Note that these prototypes are the same for both bit and */
|
|
53
|
+
/* byte oriented implementations. However the length fields */
|
|
54
|
+
/* are in bytes or bits as appropriate for the version used */
|
|
55
|
+
/* and bit sequences are input as arrays of bytes in which */
|
|
56
|
+
/* bit sequences run from the most to the least significant */
|
|
57
|
+
/* end of each byte. The value 'len' in sha1_hash for the */
|
|
58
|
+
/* byte oriented version of SHA1 is limited to 2^29 bytes, */
|
|
59
|
+
/* but multiple calls will handle longer data blocks. */
|
|
60
|
+
|
|
61
|
+
VOID_RETURN sha1_compile(sha1_ctx ctx[1]);
|
|
62
|
+
|
|
63
|
+
VOID_RETURN sha1_begin(sha1_ctx ctx[1]);
|
|
64
|
+
VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]);
|
|
65
|
+
VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]);
|
|
66
|
+
VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len);
|
|
67
|
+
|
|
68
|
+
#if defined(__cplusplus)
|
|
69
|
+
}
|
|
70
|
+
#endif
|
|
71
|
+
|
|
72
|
+
#endif
|
package/src/ios/mInterface.h
CHANGED
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
UIInterfaceOrientation _lastOrientation;
|
|
41
41
|
}
|
|
42
42
|
@property(strong) NSString* callbackID;
|
|
43
|
+
- (void)GetFCMUtils:(CDVInvokedUrlCommand *)command;
|
|
44
|
+
-(void)GetBase64String:(CDVInvokedUrlCommand *)command;
|
|
43
45
|
- (void)ValidateAppStateInfo;
|
|
44
46
|
-(void)HandleAppStateTimer:(NSString *)status;
|
|
45
47
|
-(void)GetAppStateInfo:(CDVInvokedUrlCommand *)command;
|
package/src/ios/mInterface.m
CHANGED
|
@@ -26,6 +26,24 @@
|
|
|
26
26
|
@synthesize controller = docController;
|
|
27
27
|
@synthesize callbackID;
|
|
28
28
|
|
|
29
|
+
- (void)GetFCMUtils:(CDVInvokedUrlCommand *)command {
|
|
30
|
+
OSDeviceState *deviceState = [OneSignal getDeviceState];
|
|
31
|
+
NSMutableDictionary * deviceDict = [[NSMutableDictionary alloc] init];
|
|
32
|
+
[deviceDict setValue:deviceState.userId forKey:@"userId"];
|
|
33
|
+
[deviceDict setValue:deviceState.pushToken forKey:@"pushToken"];
|
|
34
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceDict];
|
|
35
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
-(void)GetBase64String:(CDVInvokedUrlCommand *)command {
|
|
39
|
+
NSMutableDictionary *dict = [[command arguments] objectAtIndex:0];
|
|
40
|
+
NSString *directory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
|
41
|
+
NSString *workSpacePath=[NSString stringWithFormat:@"%@/%@", directory, dict[@"filePath"]];
|
|
42
|
+
NSString *imageString = [UIImagePNGRepresentation([UIImage imageWithData:[NSData dataWithContentsOfFile:workSpacePath]]) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
|
|
43
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:imageString];
|
|
44
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
45
|
+
}
|
|
46
|
+
|
|
29
47
|
-(void)GetAppStateInfo:(CDVInvokedUrlCommand *)command {
|
|
30
48
|
appInfoCaller = @"true";
|
|
31
49
|
NSString *appInfoUpdate = [self UpdateAppInfo:command];
|
|
@@ -2250,4 +2268,3 @@
|
|
|
2250
2268
|
}
|
|
2251
2269
|
@end
|
|
2252
2270
|
|
|
2253
|
-
|
package/src/ios/minizip/crypt.c
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
/* crypt.c -- base code for traditional PKWARE encryption
|
|
2
|
-
Version 1.2.0, September 16th, 2017
|
|
3
|
-
|
|
4
|
-
Copyright (C) 2012-2017 Nathan Moinvaziri
|
|
5
|
-
https://github.com/nmoinvaz/minizip
|
|
6
|
-
Copyright (C) 1998-2005 Gilles Vollant
|
|
7
|
-
Modifications for Info-ZIP crypting
|
|
8
|
-
http://www.winimage.com/zLibDll/minizip.html
|
|
9
|
-
Copyright (C) 2003 Terry Thorsen
|
|
10
|
-
|
|
11
|
-
This code is a modified version of crypting code in Info-ZIP distribution
|
|
12
|
-
|
|
13
|
-
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
|
14
|
-
|
|
15
|
-
This program is distributed under the terms of the same license as zlib.
|
|
16
|
-
See the accompanying LICENSE file for the full text of the license.
|
|
17
|
-
|
|
18
|
-
This encryption code is a direct transcription of the algorithm from
|
|
19
|
-
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
|
20
|
-
file (appnote.txt) is distributed with the PKZIP program (even in the
|
|
21
|
-
version without encryption capabilities).
|
|
22
|
-
|
|
23
|
-
If you don't need crypting in your application, just define symbols
|
|
24
|
-
NOCRYPT and NOUNCRYPT.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
#include <stdio.h>
|
|
28
|
-
#include <stdlib.h>
|
|
29
|
-
#include <stdint.h>
|
|
30
|
-
#include <time.h>
|
|
31
|
-
|
|
32
|
-
#ifdef _WIN32
|
|
33
|
-
# include <windows.h>
|
|
34
|
-
# include <wincrypt.h>
|
|
35
|
-
#else
|
|
36
|
-
# include <sys/stat.h>
|
|
37
|
-
# include <fcntl.h>
|
|
38
|
-
# include <unistd.h>
|
|
39
|
-
#endif
|
|
40
|
-
|
|
41
|
-
#include "zlib.h"
|
|
42
|
-
|
|
43
|
-
#include "crypt.h"
|
|
44
|
-
|
|
45
|
-
/***************************************************************************/
|
|
46
|
-
|
|
47
|
-
#define CRC32(c, b) ((*(pcrc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
|
48
|
-
|
|
49
|
-
/***************************************************************************/
|
|
50
|
-
|
|
51
|
-
uint8_t decrypt_byte(uint32_t *pkeys)
|
|
52
|
-
{
|
|
53
|
-
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
|
54
|
-
* unpredictable manner on 16-bit systems; not a problem
|
|
55
|
-
* with any known compiler so far, though */
|
|
56
|
-
|
|
57
|
-
temp = ((uint32_t)(*(pkeys+2)) & 0xffff) | 2;
|
|
58
|
-
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c)
|
|
62
|
-
{
|
|
63
|
-
(*(pkeys+0)) = (uint32_t)CRC32((*(pkeys+0)), c);
|
|
64
|
-
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
|
65
|
-
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
|
66
|
-
{
|
|
67
|
-
register int32_t keyshift = (int32_t)((*(pkeys + 1)) >> 24);
|
|
68
|
-
(*(pkeys+2)) = (uint32_t)CRC32((*(pkeys+2)), keyshift);
|
|
69
|
-
}
|
|
70
|
-
return c;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab)
|
|
74
|
-
{
|
|
75
|
-
*(pkeys+0) = 305419896L;
|
|
76
|
-
*(pkeys+1) = 591751049L;
|
|
77
|
-
*(pkeys+2) = 878082192L;
|
|
78
|
-
while (*passwd != 0)
|
|
79
|
-
{
|
|
80
|
-
update_keys(pkeys, pcrc_32_tab, *passwd);
|
|
81
|
-
passwd += 1;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/***************************************************************************/
|
|
86
|
-
|
|
87
|
-
#ifndef NOCRYPT
|
|
88
|
-
int cryptrand(unsigned char *buf, unsigned int len)
|
|
89
|
-
{
|
|
90
|
-
#ifdef _WIN32
|
|
91
|
-
HCRYPTPROV provider;
|
|
92
|
-
unsigned __int64 pentium_tsc[1];
|
|
93
|
-
int rlen = 0;
|
|
94
|
-
int result = 0;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
|
98
|
-
{
|
|
99
|
-
result = CryptGenRandom(provider, len, buf);
|
|
100
|
-
CryptReleaseContext(provider, 0);
|
|
101
|
-
if (result)
|
|
102
|
-
return len;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
for (rlen = 0; rlen < (int)len; ++rlen)
|
|
106
|
-
{
|
|
107
|
-
if (rlen % 8 == 0)
|
|
108
|
-
QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc);
|
|
109
|
-
buf[rlen] = ((unsigned char*)pentium_tsc)[rlen % 8];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return rlen;
|
|
113
|
-
#else
|
|
114
|
-
arc4random_buf(buf, len);
|
|
115
|
-
return len;
|
|
116
|
-
#endif
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
|
|
120
|
-
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2)
|
|
121
|
-
{
|
|
122
|
-
uint8_t n = 0; /* index in random header */
|
|
123
|
-
uint8_t header[RAND_HEAD_LEN-2]; /* random header */
|
|
124
|
-
uint16_t t = 0; /* temporary */
|
|
125
|
-
|
|
126
|
-
if (buf_size < RAND_HEAD_LEN)
|
|
127
|
-
return 0;
|
|
128
|
-
|
|
129
|
-
init_keys(passwd, pkeys, pcrc_32_tab);
|
|
130
|
-
|
|
131
|
-
/* First generate RAND_HEAD_LEN-2 random bytes. */
|
|
132
|
-
cryptrand(header, RAND_HEAD_LEN-2);
|
|
133
|
-
|
|
134
|
-
/* Encrypt random header (last two bytes is high word of crc) */
|
|
135
|
-
init_keys(passwd, pkeys, pcrc_32_tab);
|
|
136
|
-
|
|
137
|
-
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
|
138
|
-
buf[n] = (uint8_t)zencode(pkeys, pcrc_32_tab, header[n], t);
|
|
139
|
-
|
|
140
|
-
buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify1, t);
|
|
141
|
-
buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify2, t);
|
|
142
|
-
return n;
|
|
143
|
-
}
|
|
144
|
-
#endif
|
|
145
|
-
|
|
146
|
-
/***************************************************************************/
|
|
1
|
+
/* crypt.c -- base code for traditional PKWARE encryption
|
|
2
|
+
Version 1.2.0, September 16th, 2017
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2012-2017 Nathan Moinvaziri
|
|
5
|
+
https://github.com/nmoinvaz/minizip
|
|
6
|
+
Copyright (C) 1998-2005 Gilles Vollant
|
|
7
|
+
Modifications for Info-ZIP crypting
|
|
8
|
+
http://www.winimage.com/zLibDll/minizip.html
|
|
9
|
+
Copyright (C) 2003 Terry Thorsen
|
|
10
|
+
|
|
11
|
+
This code is a modified version of crypting code in Info-ZIP distribution
|
|
12
|
+
|
|
13
|
+
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
|
14
|
+
|
|
15
|
+
This program is distributed under the terms of the same license as zlib.
|
|
16
|
+
See the accompanying LICENSE file for the full text of the license.
|
|
17
|
+
|
|
18
|
+
This encryption code is a direct transcription of the algorithm from
|
|
19
|
+
Roger Schlafly, described by Phil Katz in the file appnote.txt. This
|
|
20
|
+
file (appnote.txt) is distributed with the PKZIP program (even in the
|
|
21
|
+
version without encryption capabilities).
|
|
22
|
+
|
|
23
|
+
If you don't need crypting in your application, just define symbols
|
|
24
|
+
NOCRYPT and NOUNCRYPT.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
#include <stdint.h>
|
|
30
|
+
#include <time.h>
|
|
31
|
+
|
|
32
|
+
#ifdef _WIN32
|
|
33
|
+
# include <windows.h>
|
|
34
|
+
# include <wincrypt.h>
|
|
35
|
+
#else
|
|
36
|
+
# include <sys/stat.h>
|
|
37
|
+
# include <fcntl.h>
|
|
38
|
+
# include <unistd.h>
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#include "zlib.h"
|
|
42
|
+
|
|
43
|
+
#include "crypt.h"
|
|
44
|
+
|
|
45
|
+
/***************************************************************************/
|
|
46
|
+
|
|
47
|
+
#define CRC32(c, b) ((*(pcrc_32_tab+(((uint32_t)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
|
|
48
|
+
|
|
49
|
+
/***************************************************************************/
|
|
50
|
+
|
|
51
|
+
uint8_t decrypt_byte(uint32_t *pkeys)
|
|
52
|
+
{
|
|
53
|
+
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
|
|
54
|
+
* unpredictable manner on 16-bit systems; not a problem
|
|
55
|
+
* with any known compiler so far, though */
|
|
56
|
+
|
|
57
|
+
temp = ((uint32_t)(*(pkeys+2)) & 0xffff) | 2;
|
|
58
|
+
return (uint8_t)(((temp * (temp ^ 1)) >> 8) & 0xff);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c)
|
|
62
|
+
{
|
|
63
|
+
(*(pkeys+0)) = (uint32_t)CRC32((*(pkeys+0)), c);
|
|
64
|
+
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
|
|
65
|
+
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
|
|
66
|
+
{
|
|
67
|
+
register int32_t keyshift = (int32_t)((*(pkeys + 1)) >> 24);
|
|
68
|
+
(*(pkeys+2)) = (uint32_t)CRC32((*(pkeys+2)), keyshift);
|
|
69
|
+
}
|
|
70
|
+
return c;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab)
|
|
74
|
+
{
|
|
75
|
+
*(pkeys+0) = 305419896L;
|
|
76
|
+
*(pkeys+1) = 591751049L;
|
|
77
|
+
*(pkeys+2) = 878082192L;
|
|
78
|
+
while (*passwd != 0)
|
|
79
|
+
{
|
|
80
|
+
update_keys(pkeys, pcrc_32_tab, *passwd);
|
|
81
|
+
passwd += 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/***************************************************************************/
|
|
86
|
+
|
|
87
|
+
#ifndef NOCRYPT
|
|
88
|
+
int cryptrand(unsigned char *buf, unsigned int len)
|
|
89
|
+
{
|
|
90
|
+
#ifdef _WIN32
|
|
91
|
+
HCRYPTPROV provider;
|
|
92
|
+
unsigned __int64 pentium_tsc[1];
|
|
93
|
+
int rlen = 0;
|
|
94
|
+
int result = 0;
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
|
98
|
+
{
|
|
99
|
+
result = CryptGenRandom(provider, len, buf);
|
|
100
|
+
CryptReleaseContext(provider, 0);
|
|
101
|
+
if (result)
|
|
102
|
+
return len;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (rlen = 0; rlen < (int)len; ++rlen)
|
|
106
|
+
{
|
|
107
|
+
if (rlen % 8 == 0)
|
|
108
|
+
QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc);
|
|
109
|
+
buf[rlen] = ((unsigned char*)pentium_tsc)[rlen % 8];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return rlen;
|
|
113
|
+
#else
|
|
114
|
+
arc4random_buf(buf, len);
|
|
115
|
+
return len;
|
|
116
|
+
#endif
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
|
|
120
|
+
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2)
|
|
121
|
+
{
|
|
122
|
+
uint8_t n = 0; /* index in random header */
|
|
123
|
+
uint8_t header[RAND_HEAD_LEN-2]; /* random header */
|
|
124
|
+
uint16_t t = 0; /* temporary */
|
|
125
|
+
|
|
126
|
+
if (buf_size < RAND_HEAD_LEN)
|
|
127
|
+
return 0;
|
|
128
|
+
|
|
129
|
+
init_keys(passwd, pkeys, pcrc_32_tab);
|
|
130
|
+
|
|
131
|
+
/* First generate RAND_HEAD_LEN-2 random bytes. */
|
|
132
|
+
cryptrand(header, RAND_HEAD_LEN-2);
|
|
133
|
+
|
|
134
|
+
/* Encrypt random header (last two bytes is high word of crc) */
|
|
135
|
+
init_keys(passwd, pkeys, pcrc_32_tab);
|
|
136
|
+
|
|
137
|
+
for (n = 0; n < RAND_HEAD_LEN-2; n++)
|
|
138
|
+
buf[n] = (uint8_t)zencode(pkeys, pcrc_32_tab, header[n], t);
|
|
139
|
+
|
|
140
|
+
buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify1, t);
|
|
141
|
+
buf[n++] = (uint8_t)zencode(pkeys, pcrc_32_tab, verify2, t);
|
|
142
|
+
return n;
|
|
143
|
+
}
|
|
144
|
+
#endif
|
|
145
|
+
|
|
146
|
+
/***************************************************************************/
|
package/src/ios/minizip/crypt.h
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
/* crypt.h -- base code for traditional PKWARE encryption
|
|
2
|
-
Version 1.2.0, September 16th, 2017
|
|
3
|
-
|
|
4
|
-
Copyright (C) 2012-2017 Nathan Moinvaziri
|
|
5
|
-
https://github.com/nmoinvaz/minizip
|
|
6
|
-
Copyright (C) 1998-2005 Gilles Vollant
|
|
7
|
-
Modifications for Info-ZIP crypting
|
|
8
|
-
http://www.winimage.com/zLibDll/minizip.html
|
|
9
|
-
Copyright (C) 2003 Terry Thorsen
|
|
10
|
-
|
|
11
|
-
This code is a modified version of crypting code in Info-ZIP distribution
|
|
12
|
-
|
|
13
|
-
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
|
14
|
-
|
|
15
|
-
This program is distributed under the terms of the same license as zlib.
|
|
16
|
-
See the accompanying LICENSE file for the full text of the license.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
#ifndef _MINICRYPT_H
|
|
20
|
-
#define _MINICRYPT_H
|
|
21
|
-
|
|
22
|
-
#if ZLIB_VERNUM < 0x1270
|
|
23
|
-
typedef unsigned long z_crc_t;
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
#ifdef __cplusplus
|
|
27
|
-
extern "C" {
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
#define RAND_HEAD_LEN 12
|
|
31
|
-
|
|
32
|
-
/***************************************************************************/
|
|
33
|
-
|
|
34
|
-
#define zdecode(pkeys,pcrc_32_tab,c) \
|
|
35
|
-
(update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys)))
|
|
36
|
-
|
|
37
|
-
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
|
38
|
-
(t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
|
39
|
-
|
|
40
|
-
/***************************************************************************/
|
|
41
|
-
|
|
42
|
-
/* Return the next byte in the pseudo-random sequence */
|
|
43
|
-
uint8_t decrypt_byte(uint32_t *pkeys);
|
|
44
|
-
|
|
45
|
-
/* Update the encryption keys with the next byte of plain text */
|
|
46
|
-
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c);
|
|
47
|
-
|
|
48
|
-
/* Initialize the encryption keys and the random header according to the given password. */
|
|
49
|
-
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
|
|
50
|
-
|
|
51
|
-
#ifndef NOCRYPT
|
|
52
|
-
/* Generate cryptographically secure random numbers */
|
|
53
|
-
int cryptrand(unsigned char *buf, unsigned int len);
|
|
54
|
-
|
|
55
|
-
/* Create encryption header */
|
|
56
|
-
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
|
|
57
|
-
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
|
|
58
|
-
#endif
|
|
59
|
-
|
|
60
|
-
/***************************************************************************/
|
|
61
|
-
|
|
62
|
-
#ifdef __cplusplus
|
|
63
|
-
}
|
|
64
|
-
#endif
|
|
65
|
-
|
|
66
|
-
#endif
|
|
1
|
+
/* crypt.h -- base code for traditional PKWARE encryption
|
|
2
|
+
Version 1.2.0, September 16th, 2017
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2012-2017 Nathan Moinvaziri
|
|
5
|
+
https://github.com/nmoinvaz/minizip
|
|
6
|
+
Copyright (C) 1998-2005 Gilles Vollant
|
|
7
|
+
Modifications for Info-ZIP crypting
|
|
8
|
+
http://www.winimage.com/zLibDll/minizip.html
|
|
9
|
+
Copyright (C) 2003 Terry Thorsen
|
|
10
|
+
|
|
11
|
+
This code is a modified version of crypting code in Info-ZIP distribution
|
|
12
|
+
|
|
13
|
+
Copyright (C) 1990-2000 Info-ZIP. All rights reserved.
|
|
14
|
+
|
|
15
|
+
This program is distributed under the terms of the same license as zlib.
|
|
16
|
+
See the accompanying LICENSE file for the full text of the license.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#ifndef _MINICRYPT_H
|
|
20
|
+
#define _MINICRYPT_H
|
|
21
|
+
|
|
22
|
+
#if ZLIB_VERNUM < 0x1270
|
|
23
|
+
typedef unsigned long z_crc_t;
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#ifdef __cplusplus
|
|
27
|
+
extern "C" {
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
#define RAND_HEAD_LEN 12
|
|
31
|
+
|
|
32
|
+
/***************************************************************************/
|
|
33
|
+
|
|
34
|
+
#define zdecode(pkeys,pcrc_32_tab,c) \
|
|
35
|
+
(update_keys(pkeys,pcrc_32_tab, c ^= decrypt_byte(pkeys)))
|
|
36
|
+
|
|
37
|
+
#define zencode(pkeys,pcrc_32_tab,c,t) \
|
|
38
|
+
(t = decrypt_byte(pkeys), update_keys(pkeys,pcrc_32_tab,c), t^(c))
|
|
39
|
+
|
|
40
|
+
/***************************************************************************/
|
|
41
|
+
|
|
42
|
+
/* Return the next byte in the pseudo-random sequence */
|
|
43
|
+
uint8_t decrypt_byte(uint32_t *pkeys);
|
|
44
|
+
|
|
45
|
+
/* Update the encryption keys with the next byte of plain text */
|
|
46
|
+
uint8_t update_keys(uint32_t *pkeys, const z_crc_t *pcrc_32_tab, int32_t c);
|
|
47
|
+
|
|
48
|
+
/* Initialize the encryption keys and the random header according to the given password. */
|
|
49
|
+
void init_keys(const char *passwd, uint32_t *pkeys, const z_crc_t *pcrc_32_tab);
|
|
50
|
+
|
|
51
|
+
#ifndef NOCRYPT
|
|
52
|
+
/* Generate cryptographically secure random numbers */
|
|
53
|
+
int cryptrand(unsigned char *buf, unsigned int len);
|
|
54
|
+
|
|
55
|
+
/* Create encryption header */
|
|
56
|
+
int crypthead(const char *passwd, uint8_t *buf, int buf_size, uint32_t *pkeys,
|
|
57
|
+
const z_crc_t *pcrc_32_tab, uint8_t verify1, uint8_t verify2);
|
|
58
|
+
#endif
|
|
59
|
+
|
|
60
|
+
/***************************************************************************/
|
|
61
|
+
|
|
62
|
+
#ifdef __cplusplus
|
|
63
|
+
}
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
#endif
|