| | @@ -750,10 +750,11 @@ |
| 750 | 750 | ** "json" = FOSSIL_ENABLE_JSON |
| 751 | 751 | ** "markdown" = FOSSIL_ENABLE_MARKDOWN |
| 752 | 752 | ** "unicodeCmdLine" = !BROKEN_MINGW_CMDLINE |
| 753 | 753 | ** "dynamicBuild" = FOSSIL_DYNAMIC_BUILD |
| 754 | 754 | ** "see" = USE_SEE |
| 755 | +** "hardenedSha1" = FOSSIL_HARDENED_SHA1 |
| 755 | 756 | ** |
| 756 | 757 | ** Specifying an unknown feature will return a value of false, it will not |
| 757 | 758 | ** raise a script error. |
| 758 | 759 | */ |
| 759 | 760 | static int hasfeatureCmd( |
| | @@ -766,11 +767,11 @@ |
| 766 | 767 | int rc = 0; |
| 767 | 768 | const char *zArg; |
| 768 | 769 | if( argc!=2 ){ |
| 769 | 770 | return Th_WrongNumArgs(interp, "hasfeature STRING"); |
| 770 | 771 | } |
| 771 | | - zArg = (const char *)argv[1]; |
| 772 | + zArg = argv[1]; |
| 772 | 773 | if(NULL==zArg){ |
| 773 | 774 | /* placeholder for following ifdefs... */ |
| 774 | 775 | } |
| 775 | 776 | #if defined(FOSSIL_ENABLE_SSL) |
| 776 | 777 | else if( 0 == fossil_strnicmp( zArg, "ssl\0", 4 ) ){ |
| | @@ -834,10 +835,15 @@ |
| 834 | 835 | #endif |
| 835 | 836 | #if defined(USE_SEE) |
| 836 | 837 | else if( 0 == fossil_strnicmp( zArg, "see\0", 4 ) ){ |
| 837 | 838 | rc = 1; |
| 838 | 839 | } |
| 840 | +#endif |
| 841 | +#if FOSSIL_HARDENED_SHA1 |
| 842 | + else if( 0 == fossil_strnicmp( zArg, "hardenedSha1\0", 13 ) ){ |
| 843 | + rc = 1; |
| 844 | + } |
| 839 | 845 | #endif |
| 840 | 846 | else if( 0 == fossil_strnicmp( zArg, "markdown\0", 9 ) ){ |
| 841 | 847 | rc = 1; |
| 842 | 848 | } |
| 843 | 849 | if( g.thTrace ){ |
| | @@ -844,10 +850,64 @@ |
| 844 | 850 | Th_Trace("[hasfeature %#h] => %d<br />\n", argl[1], zArg, rc); |
| 845 | 851 | } |
| 846 | 852 | Th_SetResultInt(interp, rc); |
| 847 | 853 | return TH_OK; |
| 848 | 854 | } |
| 855 | + |
| 856 | +/* |
| 857 | +** TH1 command: hash STRING ?ALGORITHM? |
| 858 | +** |
| 859 | +** Returns the cryptographic hash of the specified string. Possible values |
| 860 | +** for the ALGORITHM argument are: |
| 861 | +** |
| 862 | +** "md5" |
| 863 | +** "sha1" |
| 864 | +** "sha3-224" |
| 865 | +** "sha3-256" |
| 866 | +** "sha3-384" |
| 867 | +** "sha3-512" |
| 868 | +** |
| 869 | +** The default algorithm is "sha3-256". Specifying an unknown algorithm |
| 870 | +** will raise a script error. |
| 871 | +*/ |
| 872 | +static int hashCmd( |
| 873 | + Th_Interp *interp, |
| 874 | + void *p, |
| 875 | + int argc, |
| 876 | + const char **argv, |
| 877 | + int *argl |
| 878 | +){ |
| 879 | + Blob content; |
| 880 | + Blob cksum; |
| 881 | + const char *zAlgorithm = "sha3-256"; |
| 882 | + if( argc<2 || argc>3 ){ |
| 883 | + return Th_WrongNumArgs(interp, "hash STRING ?ALGORITHM?"); |
| 884 | + } |
| 885 | + blob_init(&content, argv[1], argl[1]); |
| 886 | + blob_zero(&cksum); |
| 887 | + if( argc>=3 ){ |
| 888 | + zAlgorithm = argv[2]; |
| 889 | + } |
| 890 | + if( 0 == fossil_strnicmp( zAlgorithm, "md5\0", 4 ) ){ |
| 891 | + md5sum_blob(&content, &cksum); |
| 892 | + }else if( 0 == fossil_strnicmp( zAlgorithm, "sha1\0", 5 ) ){ |
| 893 | + sha1sum_blob(&content, &cksum); |
| 894 | + }else if( 0 == fossil_strnicmp( zAlgorithm, "sha3-224\0", 9 ) ){ |
| 895 | + sha3sum_blob(&content, 224, &cksum); |
| 896 | + }else if( 0 == fossil_strnicmp( zAlgorithm, "sha3-256\0", 9 ) ){ |
| 897 | + sha3sum_blob(&content, 256, &cksum); |
| 898 | + }else if( 0 == fossil_strnicmp( zAlgorithm, "sha3-384\0", 9 ) ){ |
| 899 | + sha3sum_blob(&content, 384, &cksum); |
| 900 | + }else if( 0 == fossil_strnicmp( zAlgorithm, "sha3-512\0", 9 ) ){ |
| 901 | + sha3sum_blob(&content, 512, &cksum); |
| 902 | + }else{ |
| 903 | + Th_SetResult(interp, "unknown hash algorithm", -1); |
| 904 | + return TH_ERROR; |
| 905 | + } |
| 906 | + Th_SetResult(interp, blob_str(&cksum), -1); |
| 907 | + return TH_OK; |
| 908 | +} |
| 849 | 909 | |
| 850 | 910 | |
| 851 | 911 | /* |
| 852 | 912 | ** TH1 command: tclReady |
| 853 | 913 | ** |
| | @@ -1961,10 +2021,11 @@ |
| 1961 | 2021 | {"glob_match", globMatchCmd, 0}, |
| 1962 | 2022 | {"globalState", globalStateCmd, 0}, |
| 1963 | 2023 | {"httpize", httpizeCmd, 0}, |
| 1964 | 2024 | {"hascap", hascapCmd, (void*)&zeroInt}, |
| 1965 | 2025 | {"hasfeature", hasfeatureCmd, 0}, |
| 2026 | + {"hash", hashCmd, 0}, |
| 1966 | 2027 | {"html", putsCmd, (void*)&aFlags[0]}, |
| 1967 | 2028 | {"htmlize", htmlizeCmd, 0}, |
| 1968 | 2029 | {"http", httpCmd, 0}, |
| 1969 | 2030 | {"insertCsrf", insertCsrfCmd, 0}, |
| 1970 | 2031 | {"linecount", linecntCmd, 0}, |
| 1971 | 2032 | |