@ibgib/core-gib 0.0.49 → 0.0.50

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.
Files changed (46) hide show
  1. package/dist/common/encrypt/encrypt-constants.d.mts +0 -4
  2. package/dist/common/encrypt/encrypt-constants.d.mts.map +1 -1
  3. package/dist/common/encrypt/encrypt-constants.mjs +0 -4
  4. package/dist/common/encrypt/encrypt-constants.mjs.map +1 -1
  5. package/dist/common/encrypt/encrypt-helper.d.mts +2 -0
  6. package/dist/common/encrypt/encrypt-helper.d.mts.map +1 -0
  7. package/dist/common/encrypt/encrypt-helper.mjs +2 -0
  8. package/dist/common/encrypt/encrypt-helper.mjs.map +1 -0
  9. package/dist/common/encrypt/encrypt-types.d.mts +0 -34
  10. package/dist/common/encrypt/encrypt-types.d.mts.map +1 -1
  11. package/dist/common/encrypt/encrypt-types.mjs +0 -4
  12. package/dist/common/encrypt/encrypt-types.mjs.map +1 -1
  13. package/dist/common/other/ibgib-helper.d.mts +15 -1
  14. package/dist/common/other/ibgib-helper.d.mts.map +1 -1
  15. package/dist/common/other/ibgib-helper.mjs +17 -4
  16. package/dist/common/other/ibgib-helper.mjs.map +1 -1
  17. package/dist/common/secret/secret-constants.d.mts +30 -0
  18. package/dist/common/secret/secret-constants.d.mts.map +1 -0
  19. package/dist/common/secret/secret-constants.mjs +42 -0
  20. package/dist/common/secret/secret-constants.mjs.map +1 -0
  21. package/dist/common/secret/secret-helper.d.mts +85 -0
  22. package/dist/common/secret/secret-helper.d.mts.map +1 -0
  23. package/dist/common/secret/secret-helper.mjs +358 -0
  24. package/dist/common/secret/secret-helper.mjs.map +1 -0
  25. package/dist/common/secret/secret-types.d.mts +192 -0
  26. package/dist/common/secret/secret-types.d.mts.map +1 -0
  27. package/dist/common/secret/secret-types.mjs +8 -0
  28. package/dist/common/secret/secret-types.mjs.map +1 -0
  29. package/dist/common/secret/secret.respec.d.mts +7 -0
  30. package/dist/common/secret/secret.respec.d.mts.map +1 -0
  31. package/dist/common/secret/secret.respec.mjs +160 -0
  32. package/dist/common/secret/secret.respec.mjs.map +1 -0
  33. package/dist/witness/space/metaspace/metaspace-base.d.mts +2 -1
  34. package/dist/witness/space/metaspace/metaspace-base.d.mts.map +1 -1
  35. package/dist/witness/space/metaspace/metaspace-base.mjs +24 -18
  36. package/dist/witness/space/metaspace/metaspace-base.mjs.map +1 -1
  37. package/dist/witness/space/metaspace/metaspace-types.d.mts +2 -1
  38. package/dist/witness/space/metaspace/metaspace-types.d.mts.map +1 -1
  39. package/package.json +3 -3
  40. package/src/common/other/ibgib-helper.mts +28 -3
  41. package/src/common/secret/secret-constants.mts +13 -0
  42. package/src/common/secret/secret-helper.mts +211 -54
  43. package/src/common/secret/secret-types.mts +138 -8
  44. package/src/common/secret/secret.respec.mts +144 -5
  45. package/src/witness/space/metaspace/metaspace-base.mts +3 -2
  46. package/src/witness/space/metaspace/metaspace-types.mts +1 -1
@@ -18,10 +18,14 @@ const maam = `[${import.meta.url}]`, sir = maam;
18
18
 
19
19
  import {
20
20
  extractErrorMsg, delay, getSaferSubstring,
21
- getTimestampInTicks, getUUID, pretty,
21
+ getTimestampInTicks, getUUID, pretty, HashAlgorithm, clone,
22
22
  } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
23
23
 
24
- import { GLOBAL_LOG_A_LOT } from '../../ibgib-constants.mjs';
24
+ import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
25
+ import { getCheckIfPasswordProbablyCorrectInfo, passwordProbablyCorrect } from './secret-helper.mjs';
26
+ import { hash16816 } from '../other/ibgib-helper.mjs';
27
+ import { DEFAULT_PASSWORD_CHECK_SUBSTRING_LENGTH } from './secret-constants.mjs';
28
+
25
29
  /**
26
30
  * for verbose logging
27
31
  */
@@ -29,8 +33,143 @@ const logalot = GLOBAL_LOG_A_LOT; // change this when you want to turn off verbo
29
33
 
30
34
  const lcFile: string = `[${pathUtils.basename(import.meta.url)}]`;
31
35
 
32
- await respecfully(maam, `when testing stuff...`, async () => {
33
- await ifWe(maam, `should happen to do...`, async () => {
34
- iReckon(maam, true).asTo('42').isGonnaBe(false);
36
+ const correctPasswords = [
37
+ 'yo',
38
+ 'hey this is a password',
39
+ 'jwoiejf oiwejf oiewjf owiefhw9e8hf982y98y2398f 2398f oijsd oifj woeihfew9hg 9we8u98 u34793824798au s9d8u 9a8syg 98ywheg y98uy9*(*^*&#^ $(*&#@( *$& @(#*$&(* #@^T%(YIUdyf 98wye fuwehfiu hweiufh iugh iuh j'
40
+ ];
41
+ const substringLength = DEFAULT_PASSWORD_CHECK_SUBSTRING_LENGTH;
42
+
43
+ const recursionCount = 168;
44
+ const algorithm: HashAlgorithm = 'SHA-256';
45
+ const saltPrependedPerHash = '';
46
+
47
+ const blockName = `CheckIfPasswordProbablyCorrect`;
48
+ await respecfully(maam, blockName, async () => {
49
+ const lc = `${lcFile}[${blockName}]`;
50
+
51
+ if (logalot) { console.time(lc) }
52
+
53
+ await respecfully(maam, `checking passwords`, async () => {
54
+ await ifWe(maam, `ensure correct password always succeeds`, async () => {
55
+ // these are to mimic legitimate setting of hash16816 substring and
56
+ // subsequent legit correct password entries. they should always
57
+ // succeed, i.e., the hash should always contain the substring.
58
+ const iterationsToCheck = 10;
59
+
60
+ let failed = false;
61
+ for (let i = 0; i < correctPasswords.length; i++) {
62
+ const password = correctPasswords[i];
63
+ const fullHash = await hash16816({
64
+ s: password,
65
+ algorithm,
66
+ recursionCount,
67
+ saltPrependedPerHash,
68
+ });
69
+ for (let num = 0; num < iterationsToCheck; num++) {
70
+ const public_checkInfo = await getCheckIfPasswordProbablyCorrectInfo({
71
+ password,
72
+ substringLength,
73
+ algorithm,
74
+ saltPrependedPerHash,
75
+ recursionCount
76
+ });
77
+ const { substring } = public_checkInfo;
78
+ // manually check (requires us to know internals of
79
+ // passwordProbablyCorrect fn)
80
+ if (!fullHash.includes(substring)) {
81
+ failed = true;
82
+ break;
83
+ }
84
+ // check directly via the fn consumer will use
85
+ const resProbablyCorrect = await passwordProbablyCorrect({
86
+ password,
87
+ checkInfo: clone(public_checkInfo),
88
+ });
89
+ if (!resProbablyCorrect) {
90
+ failed = true;
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ iReckon(sir, failed).asTo('failed').isGonnaBeFalse();
96
+ });
35
97
  });
98
+
99
+ if (logalot) { console.timeLog(lc) }
100
+
101
+ await respecfully(maam, `bruteforcing check`, async () => {
102
+ await ifWe(maam, `try to brute force, we get a collision`, async () => {
103
+ /**
104
+ * I've done larger numbers than these, but would be a waste of time to
105
+ * do more now. change this as needed for custom testing.
106
+ */
107
+ const numBruteForceTests = 3;
108
+ /**
109
+ * i just want to average the iterations required to tweak what i should
110
+ * be using as a substringLength.
111
+ */
112
+ let totalAttemptsForFalseCollisions = 0;
113
+ for (let i = 0; i < numBruteForceTests; i++) {
114
+ const correctPassword = correctPasswords[i % correctPasswords.length];
115
+ const correctFullHash = await hash16816({
116
+ s: correctPassword,
117
+ algorithm,
118
+ recursionCount,
119
+ saltPrependedPerHash,
120
+ });
121
+ /**
122
+ * when initially creating the secret, the user will store this
123
+ * known substring in the `secretInfo.passwordProbablyCorrectSubstring`.
124
+ * from the attacker's POV this substring is public knowledge, and
125
+ * the attacker is going to try to brute force against this
126
+ * substring. we want there to be at least one collistion that has
127
+ * this substring.
128
+ *
129
+ * "public" as in the would-be brute forcer knows this (and other
130
+ * check info) as public metadata
131
+ */
132
+ const public_checkInfo = await getCheckIfPasswordProbablyCorrectInfo({
133
+ password: correctPassword,
134
+ substringLength,
135
+ algorithm,
136
+ recursionCount,
137
+ saltPrependedPerHash,
138
+ });
139
+ const { substring: publicSubstring } = public_checkInfo;
140
+ /**
141
+ * some arbitrarily "large" number (really this will be much higher
142
+ * but we are testing in a respec here).
143
+ */
144
+ const bruteForceAttempts = 1_000_000;
145
+ let foundFalseCollision = false;
146
+ for (let j = 0; j < bruteForceAttempts; j++) {
147
+ const passwordAttempt = j.toString();
148
+ const fullHashAttempt = await hash16816({
149
+ s: passwordAttempt,
150
+ algorithm,
151
+ recursionCount,
152
+ saltPrependedPerHash,
153
+ });
154
+ if (fullHashAttempt.includes(publicSubstring)) {
155
+ // their invalid password attempt found a false collision
156
+ foundFalseCollision = true;
157
+ totalAttemptsForFalseCollisions += j;
158
+ console.log(`j: ${j}`);
159
+ console.log(`publicSubstring: ${publicSubstring}`);
160
+ console.log(`fullHashAttempt: ${fullHashAttempt}`);
161
+ console.log(`correctFullHash: ${correctFullHash}`);
162
+ break;
163
+ }
164
+ }
165
+ iReckon(maam, foundFalseCollision).asTo('foundFalseCollision').isGonnaBeTrue();
166
+ // not really for testing, but i want to see the average attempts required
167
+ let averageAttemptsPerFalseCollision = Math.floor(totalAttemptsForFalseCollisions / (i + 1));
168
+ console.log(`averageAttemptsPerFalseCollision: ${averageAttemptsPerFalseCollision}`);
169
+ }
170
+ });
171
+ });
172
+
173
+ if (logalot) { console.timeEnd(lc) }
174
+
36
175
  });
@@ -25,7 +25,6 @@ import { RootData } from '../../../common/root/root-types.mjs';
25
25
  import {
26
26
  CiphertextData, CiphertextIbGib_V1, CiphertextRel8ns,
27
27
  EncryptionData_V1, EncryptionIbGib, EncryptionInfo_EncryptGib,
28
- SecretData_V1, SecretIbGib_V1, SecretInfo_Password
29
28
  } from '../../../common/encrypt/encrypt-types.mjs';
30
29
  import { RobbotIbGib_V1 } from '../../../witness/robbot/robbot-types.mjs';
31
30
  import { AppIbGib_V1 } from '../../../witness/app/app-types.mjs';
@@ -55,7 +54,7 @@ import { IbGibCacheService } from '../../../common/cache/cache-types.mjs';
55
54
  import { BOOTSTRAP_DATA_KNOWN_SPACE_IDS_KEY, BOOTSTRAP_IBGIB_ADDR } from '../../../witness/space/bootstrap/bootstrap-constants.mjs';
56
55
  import { DEFAULT_LOCAL_SPACE_DESCRIPTION, DEFAULT_LOCAL_SPACE_POLLING_INTERVAL_MS, DEFAULT_MAX_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE, DEFAULT_MS_BETWEEN_RETRIES_GET_DEPENDENCY_GRAPH_OUTERSPACE, DEFAULT_SECONDS_VALID_LOCAL, PERSIST_OPTS_AND_RESULTS_IBGIBS_DEFAULT, SYNC_SPACE_REL8N_NAME } from '../../../witness/space/space-constants.mjs';
57
56
  import { IBGIB_BASE_DIR, IBGIB_BASE_SUBPATH, IBGIB_BIN_SUBPATH, IBGIB_DNA_SUBPATH, IBGIB_ENCODING, IBGIB_IBGIBS_SUBPATH, IBGIB_META_SUBPATH } from '../../../witness/space/filesystem-space/filesystem-constants.mjs';
58
- import { DEFAULT_ENCRYPTION_HASH_ALGORITHM, DEFAULT_ENCRYPTION_INITIAL_RECURSIONS, DEFAULT_ENCRYPTION_RECURSIONS_PER_HASH, DEFAULT_ENCRYPTION_SALT_STRATEGY, ENCRYPTION_REL8N_NAME, SECRET_REL8N_NAME } from '../../../common/encrypt/encrypt-constants.mjs';
57
+ import { DEFAULT_ENCRYPTION_HASH_ALGORITHM, DEFAULT_ENCRYPTION_INITIAL_RECURSIONS, DEFAULT_ENCRYPTION_RECURSIONS_PER_HASH, DEFAULT_ENCRYPTION_SALT_STRATEGY, ENCRYPTION_REL8N_NAME, } from '../../../common/encrypt/encrypt-constants.mjs';
59
58
  import { ROBBOT_REL8N_NAME } from '../../../witness/robbot/robbot-constants.mjs';
60
59
  import { APP_REL8N_NAME } from '../../../witness/app/app-constants.mjs';
61
60
  import { AUTOSYNC_ALWAYS_REL8N_NAME } from '../../../common/other/other-constants.mjs';
@@ -72,6 +71,8 @@ import { ObservableWitness, } from '../../../common/pubsub/observable/observable
72
71
  import { SubjectWitness } from '../../../common/pubsub/subject/subject-types.mjs';
73
72
  import { SubscriptionWitness } from '../../../common/pubsub/subscription/subscription-types.mjs';
74
73
  import { fnObs } from '../../../common/pubsub/observer/observer-helper.mjs';
74
+ import { SecretData_V1, SecretIbGib_V1, SecretInfo_Password } from '../../../common/secret/secret-types.mjs';
75
+ import { SECRET_REL8N_NAME } from '../../../common/secret/secret-constants.mjs';
75
76
 
76
77
  const logalot = GLOBAL_LOG_A_LOT;
77
78
 
@@ -22,13 +22,13 @@ import { RootData } from '../../../common/root/root-types.mjs';
22
22
  import {
23
23
  CiphertextData, CiphertextIbGib_V1, CiphertextRel8ns,
24
24
  EncryptionData_V1, EncryptionIbGib, EncryptionInfo_EncryptGib,
25
- SecretData_V1, SecretIbGib_V1, SecretInfo_Password
26
25
  } from '../../../common/encrypt/encrypt-types.mjs';
27
26
  import { RobbotIbGib_V1, RobbotPromptResult } from '../../../witness/robbot/robbot-types.mjs';
28
27
  import { AppIbGib_V1, AppPromptResult } from '../../../witness/app/app-types.mjs';
29
28
  import { rel8ToSpecialIbGib, } from '../../../witness/space/space-helper.mjs';
30
29
  import { GetDependencyGraphOptions } from '../../../common/other/graph-helper.mjs';
31
30
  import { ObservableWitness, ObservableWitnessAny } from '../../../common/pubsub/observable/observable-types.mjs';
31
+ import { SecretData_V1, SecretIbGib_V1 } from '../../../common/secret/secret-types.mjs';
32
32
 
33
33
  export interface CreateLocalSpaceOptions {
34
34
  allowCancel: boolean;