| 198 | |
| 199 | In addition, with Lloyd Milligan's permission, I used the extensible framework he has written to use to call different algorithms based on configuration. The Public Entry Point, XUSHSHP, references these as follows: |
| 200 | {{{ |
| 201 | XUSHSHP ;SF/STAFF - HASHING ROUTINE FOR SIG BLOCK IN FILE 200 ;2013-02-26 2:32 PM |
| 202 | ;;8.0;KERNEL;;Jul 10, 1995;Build 2 |
| 203 | ; |
| 204 | HASH ; PEP: HASH; Fallthrough |
| 205 | D X^UJOXCALL("HASH/DIGEST") |
| 206 | Q |
| 207 | EN ; PEP: Encrypt |
| 208 | D X^UJOXCALL("ENCRYPT STRING") |
| 209 | Q |
| 210 | DE ; PEP: Decrypt |
| 211 | D X^UJOXCALL("DECRYPT STRING") |
| 212 | Q |
| 213 | }}} |
| 214 | |
| 215 | UJOXCALL is: |
| 216 | {{{ |
| 217 | UJOXCALL ;VEN/SMH - External APIs call wrapper ;2013-02-26 3:38 PM |
| 218 | ;;1.0;JORDAN SPECIFIC MODIFICATIONS |
| 219 | Q |
| 220 | X(APINAME) ; Private Proc; Call API based on files |
| 221 | ; Input: APINAME, by Value. External API Name in file 400000001.1 |
| 222 | ; Output: None. Executes API. API determines Input and Output variables |
| 223 | ; |
| 224 | N IEN S IEN=$O(^UJO(400000001.1,"B",APINAME,"")) Q:'IEN ; IEN of API, DINUMMED in imp specific code file (400000001.3) |
| 225 | I $L($G(^UJO(400000001.3,IEN,1))) X ^(1) QUIT ; Try Implementation specific first |
| 226 | I $L($G(^UJO(400000001.1,IEN,2))) X ^(2) QUIT ; Otherwise, use default one |
| 227 | ; |
| 228 | ; |
| 229 | ; |
| 230 | RUNTESTS I $L($T(EN^XTMUNIT)) S IO=$P,DIQUIET=1 D DT^DICRW,EN^XTMUNIT($T(+0),1) QUIT |
| 231 | TESTAPI ; @TEST - Test calling X(APINAME) with existent and non-existent entries. |
| 232 | N X,X1,X2 |
| 233 | D X("UNIT TEST ENTRY") |
| 234 | D CHKEQ^XTMUNIT(X,"HELLO WORLD","API wasn't called") |
| 235 | ; |
| 236 | N STR S STR="HELLO WORLD2" |
| 237 | S X=STR,X1="LKJSDF",X2=23432 |
| 238 | D X("ENCRYPT STRING") |
| 239 | D CHKTF^XTMUNIT(X'="HELLO WORLD2","Encrypt failed") |
| 240 | D X("DECRYPT STRING") |
| 241 | D CHKEQ^XTMUNIT(X,"HELLO WORLD2","Encrypt/Decrypt failed") |
| 242 | ; |
| 243 | D X("LKSJDKLFDF") ; Make sure there is no crash |
| 244 | QUIT |
| 245 | }}} |
| 246 | |
| 247 | The extensible framework uses the file UJO SUPPORTED API (400000001.1) to decide what code to execute. Each entry in this file defines an API that can be called externally from the |
| 248 | Mumps Database. Entries in UJO IMPLEMENTATION-SPECIFIC API (400000001.3) file are DINUMMED to this file and override the default implementation of the API specified in this |
| 249 | file if a DINUMMED entry is present in the other file. |
| 250 | |
| 251 | |
| 252 | The relevant entries in the files are: |
| 253 | {{{ |
| 254 | Output from what File: UJO SUPPORTED API// (4 entries) |
| 255 | Select UJO SUPPORTED API NAME: HASH/DIGEST |
| 256 | Another one: ENCRYPT STRING |
| 257 | Another one: DECRYPT STRING |
| 258 | Another one: |
| 259 | Standard Captioned Output? Yes// (Yes) |
| 260 | Include COMPUTED fields: (N/Y/R/B): NO// - No record number (IEN), no Computed |
| 261 | Fields |
| 262 | |
| 263 | NAME: HASH/DIGEST APPLICATION GROUP: KERNEL |
| 264 | DATE CREATED: FEB 25,2013 RESPONSIBLE PERSON: EHS/SW |
| 265 | SUPPORTED VARIABLE: X ALWAYS DEFINED: YES |
| 266 | BRIEF DESCRIPTION: String to hash |
| 267 | DEFAULT XECUTE: S X=$$UP^XLFSTR(X) |
| 268 | REMARKS: |
| 269 | Function provides functionality of a password hash so that the original passwor |
| 270 | d cannot be decrypted from the hash. |
| 271 | See http://crackstation.net/hashing-security.htm |
| 272 | |
| 273 | |
| 274 | NAME: ENCRYPT STRING APPLICATION GROUP: KERNEL |
| 275 | DATE CREATED: FEB 25,2013 RESPONSIBLE PERSON: EHS/SW |
| 276 | SUPPORTED VARIABLE: X ALWAYS DEFINED: YES |
| 277 | BRIEF DESCRIPTION: String to be encrypted |
| 278 | SUPPORTED VARIABLE: X1 ALWAYS DEFINED: YES |
| 279 | BRIEF DESCRIPTION: encryption salt/password |
| 280 | SUPPORTED VARIABLE: X2 ALWAYS DEFINED: YES |
| 281 | BRIEF DESCRIPTION: encryption salt/password |
| 282 | DEFAULT XECUTE: Q |
| 283 | REMARKS: |
| 284 | Encrypts data using a password/salt |
| 285 | |
| 286 | The variables X1 and X2 are values to be decided upon by the programmer |
| 287 | calling this utility. |
| 288 | |
| 289 | |
| 290 | NAME: DECRYPT STRING APPLICATION GROUP: KERNEL |
| 291 | DATE CREATED: FEB 25,2013 RESPONSIBLE PERSON: EHS/SW |
| 292 | SUPPORTED VARIABLE: X ALWAYS DEFINED: YES |
| 293 | BRIEF DESCRIPTION: Encrypted string to be decrypted |
| 294 | SUPPORTED VARIABLE: X1 ALWAYS DEFINED: YES |
| 295 | BRIEF DESCRIPTION: Encryption salt/password |
| 296 | SUPPORTED VARIABLE: X2 ALWAYS DEFINED: YES |
| 297 | BRIEF DESCRIPTION: Encryption salt/password |
| 298 | DEFAULT XECUTE: Q |
| 299 | REMARKS: |
| 300 | Decrypts encrypted text using X1 and X2. |
| 301 | If X1 and X2 are different from what was used to encrypt the string, |
| 302 | the encryption will fail. |
| 303 | |
| 304 | |
| 305 | Select OPTION: INQUIRE TO FILE ENTRIES |
| 306 | |
| 307 | |
| 308 | |
| 309 | Output from what File: UJO SUPPORTED API// UJO,IM,S UJO IMPLEMENTATION-SPECIFIC |
| 310 | API (3 entries) |
| 311 | Select UJO IMPLEMENTATION-SPECIFIC API NAME: HASH/DIGEST |
| 312 | Another one: ENC RYPT STRING |
| 313 | Another one: DEC RYPT STRING |
| 314 | Another one: |
| 315 | Standard Captioned Output? Yes// (Yes) |
| 316 | Include COMPUTED fields: (N/Y/R/B): NO// - No record number (IEN), no Computed |
| 317 | Fields |
| 318 | |
| 319 | NAME: HASH/DIGEST XECUTE: D HASH^UJOSHSHP |
| 320 | |
| 321 | |
| 322 | NAME: ENCRYPT STRING XECUTE: D EN^UJOSHSHP |
| 323 | |
| 324 | |
| 325 | NAME: DECRYPT STRING XECUTE: D DE^UJOSHSHP |
| 326 | }}} |
| 327 | |