├── .gitignore ├── LICENSE.md ├── README.md ├── certs ├── ca.crt ├── client │ ├── client.crt │ ├── client.key │ └── client.p12 └── server │ ├── server.crt │ └── server.key ├── digest-auth-session-lib ├── DigestManager.cpp ├── DigestManager.h ├── Digestinfo.cpp ├── Digestinfo.h ├── IDigestListener.h ├── Makefile ├── digest-auth-session.pro ├── digeststruct.h ├── libs │ ├── httpserverimpl │ │ ├── clientSocket.h │ │ └── httpserver.h │ ├── httpserverinter │ │ ├── IClientEventListener.h │ │ └── IHttpClient.h │ ├── libhttpServer.a │ ├── libhttpdecoder.a │ ├── protocol │ │ ├── http │ │ │ ├── httpconstants.h │ │ │ ├── httpdecoder.h │ │ │ ├── httpdecoder_global.h │ │ │ ├── httpparser.h │ │ │ └── httpstates.h │ │ └── inter │ │ │ └── http │ │ │ ├── IhttpFrame.h │ │ │ ├── httpconsumer.h │ │ │ └── httpframe.h │ └── utils │ │ └── stringutils.h ├── release │ ├── DigestManager.h │ ├── Digestinfo.h │ ├── IDigestListener.h │ ├── digeststruct.h │ ├── libdigestauthsession.a │ ├── libs │ │ ├── httpserverimpl │ │ │ ├── clientSocket.h │ │ │ └── httpserver.h │ │ ├── httpserverinter │ │ │ ├── IClientEventListener.h │ │ │ └── IHttpClient.h │ │ ├── protocol │ │ │ ├── http │ │ │ │ ├── httpconstants.h │ │ │ │ ├── httpdecoder.h │ │ │ │ ├── httpdecoder_global.h │ │ │ │ ├── httpparser.h │ │ │ │ └── httpstates.h │ │ │ └── inter │ │ │ │ └── http │ │ │ │ ├── IhttpFrame.h │ │ │ │ ├── httpconsumer.h │ │ │ │ └── httpframe.h │ │ └── utils │ │ │ └── stringutils.h │ └── utils │ │ └── stringutil.h └── utils │ ├── stringutil.cpp │ └── stringutil.h ├── digest-auth-session-test ├── ClientSocketHandler.cpp ├── ClientSocketHandler.h ├── HashDigestListener.cpp ├── HashDigestListener.h ├── Makefile ├── SslHandler.cpp ├── SslHandler.h ├── digest-auth-session-test.pro ├── main.cpp ├── release │ ├── ClientSocketHandler.h │ ├── HashDigestListener.h │ ├── SslHandler.h │ ├── digest-auth-session-test │ └── utils │ │ ├── fileutils.h │ │ └── stringutil.h └── utils │ ├── fileutils.cpp │ ├── fileutils.h │ ├── stringutil.cpp │ └── stringutil.h ├── memcheck.suppress ├── test.png └── test_authentication_session.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | *.o 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Bertrand Martel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /certs/ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEpzCCA4+gAwIBAgIJAKpq46muqS1dMA0GCSqGSIb3DQEBBQUAMIGTMQswCQYD 3 | VQQGEwJGUjEOMAwGA1UECBMFUGFyaXMxDjAMBgNVBAcTBVBhcmlzMRAwDgYDVQQK 4 | Ewdha2luYXJ1MRAwDgYDVQQLEwdha2luYXJ1MRgwFgYDVQQDEw9XZWJzb2NrZXRT 5 | ZXJ2ZXIxJjAkBgkqhkiG9w0BCQEWF2tpcnVhem9sZGlrOTJAZ21haWwuY29tMB4X 6 | DTE1MDUxNjAyNDk0MVoXDTI1MDUxMzAyNDk0MVowgZMxCzAJBgNVBAYTAkZSMQ4w 7 | DAYDVQQIEwVQYXJpczEOMAwGA1UEBxMFUGFyaXMxEDAOBgNVBAoTB2FraW5hcnUx 8 | EDAOBgNVBAsTB2FraW5hcnUxGDAWBgNVBAMTD1dlYnNvY2tldFNlcnZlcjEmMCQG 9 | CSqGSIb3DQEJARYXa2lydWF6b2xkaWs5MkBnbWFpbC5jb20wggEiMA0GCSqGSIb3 10 | DQEBAQUAA4IBDwAwggEKAoIBAQDE5fwn6uxk0Ge06EIHQGDGdHHTgUxo8nzAOREb 11 | vUTc/L55qeeJeI/CTc9c3ynxGsLNlr/5C7rfu15lBYQNprqTFDBjVKWuXB6OTvrb 12 | +IYzcInfOQ2Q94fYMK2GVKW+BJICKxZpG9sQvQR6IenEBmWLb5f1ZyTJa3A1/UKP 13 | TWoNkybVstZHNxyNFKNz9WAUPlNJjOqNKjpaaohkVF+ELKAoi05/kSQZNKrzRRjW 14 | mq4tsmrRLnQLDPVm5xU0pIA49IDEEs5dnE0rIpcgfISYKiMBXMTRb24wRC/FCjcy 15 | PL8u4j2IFOJqyaQeBJOz2OyZ+Ke7t0uyu1c5vQYSt+ml2AajAgMBAAGjgfswgfgw 16 | HQYDVR0OBBYEFAFLgPdQ2d4VA1B4l7xkS39kKiKwMIHIBgNVHSMEgcAwgb2AFAFL 17 | gPdQ2d4VA1B4l7xkS39kKiKwoYGZpIGWMIGTMQswCQYDVQQGEwJGUjEOMAwGA1UE 18 | CBMFUGFyaXMxDjAMBgNVBAcTBVBhcmlzMRAwDgYDVQQKEwdha2luYXJ1MRAwDgYD 19 | VQQLEwdha2luYXJ1MRgwFgYDVQQDEw9XZWJzb2NrZXRTZXJ2ZXIxJjAkBgkqhkiG 20 | 9w0BCQEWF2tpcnVhem9sZGlrOTJAZ21haWwuY29tggkAqmrjqa6pLV0wDAYDVR0T 21 | BAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAGu959FFkWld0JOUIY/OilSOhDEIU 22 | 0fF49npXE2uPKFe4Le43UZgyoqnt/hlMiBT5OnSiN5musVgwcgt8Bf1bBHrhlRB5 23 | E0VF7/4M+4vSM1FNRTQMQlJ+2ZUjy89dqcBfQJkeJD++ntcG/ozoqsXFpV0jHyp+ 24 | Vo1THfl/+xOApVuBecBbQHDRN8loeCoCViNU80FU9Kzdplrv0fYkSuht7C9QdEv+ 25 | x/QQ7pdp4w11JFxeZo5A0AgFuZ5qBmrSsUxEmv/2lKFjqZoxG4Sq0sOjZZd9U7jf 26 | 9y4gyh1PKDbmn8nuHuTrpzjSRURqhpr2iQHqtyU8ZtjwrrHrZuahcSK0Pg== 27 | -----END CERTIFICATE----- 28 | -------------------------------------------------------------------------------- /certs/client/client.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 2 (0x2) 5 | Signature Algorithm: md5WithRSAEncryption 6 | Issuer: C=FR, ST=Paris, L=Paris, O=akinaru, OU=akinaru, CN=WebsocketServer/emailAddress=bmartel.fr@gmail.com 7 | Validity 8 | Not Before: May 16 02:51:42 2015 GMT 9 | Not After : May 13 02:51:42 2025 GMT 10 | Subject: C=FR, ST=Paris, O=akinaru, OU=akinaru, CN=websocket-client1/emailAddress=bmartel.fr@gmail.com 11 | Subject Public Key Info: 12 | Public Key Algorithm: rsaEncryption 13 | Public-Key: (2048 bit) 14 | Modulus: 15 | 00:d4:5e:b7:ad:ee:88:eb:43:b1:cd:0b:92:8a:48: 16 | ab:ed:7f:2f:be:d1:bb:ee:79:a7:0d:1e:14:1b:40: 17 | d1:c5:51:c0:8a:8d:0e:b8:0c:5b:19:15:2f:e3:ee: 18 | 24:a5:8f:aa:04:a2:3b:8b:8d:3f:2f:0d:1b:95:fc: 19 | f5:1f:7f:26:55:4c:b0:d6:74:d4:7b:9f:8e:a1:ab: 20 | 52:6b:59:55:33:e7:15:c6:af:8b:1a:dd:54:fc:37: 21 | 0a:87:ad:6f:5f:71:36:9c:1d:ab:c0:b9:6f:5e:b4: 22 | d9:35:69:ee:44:dd:83:be:50:8d:88:fa:2c:93:d6: 23 | a4:00:7f:16:8d:d1:39:da:48:77:0e:cb:b4:1d:2e: 24 | 88:a5:5e:e7:5d:c7:88:dd:06:f6:00:8e:fb:ad:e4: 25 | 62:e9:0e:68:99:57:03:eb:4a:20:1c:c4:a6:ce:ef: 26 | 56:da:e3:fb:a4:c3:f0:04:9c:68:b8:b7:07:98:a4: 27 | 29:ec:68:ff:46:d6:6f:14:ca:d9:53:9e:66:ba:d5: 28 | ed:da:e4:00:6c:9c:f4:59:9b:b7:e1:40:40:09:df: 29 | e3:7a:54:ff:56:72:72:55:10:2c:a1:00:62:3a:7e: 30 | c0:9c:d0:b3:4b:8a:44:b7:53:2f:d1:9b:3b:8d:94: 31 | 33:c6:8d:38:1c:bf:1c:be:62:fb:54:24:cf:95:f2: 32 | 31:9b 33 | Exponent: 65537 (0x10001) 34 | X509v3 extensions: 35 | X509v3 Basic Constraints: 36 | CA:FALSE 37 | Netscape Comment: 38 | OpenSSL Generated Certificate 39 | X509v3 Subject Key Identifier: 40 | 9F:00:4A:EB:F5:E2:3E:42:C4:FC:1B:2B:D1:A4:E3:AC:65:E0:56:09 41 | X509v3 Authority Key Identifier: 42 | keyid:01:4B:80:F7:50:D9:DE:15:03:50:78:97:BC:64:4B:7F:64:2A:22:B0 43 | DirName:/C=FR/ST=Paris/L=Paris/O=akinaru/OU=akinaru/CN=WebsocketServer/emailAddress=bmartel.fr@gmail.com 44 | serial:AA:6A:E3:A9:AE:A9:2D:5D 45 | 46 | Signature Algorithm: md5WithRSAEncryption 47 | 19:9b:92:a9:d9:b7:67:6c:45:c5:06:de:a4:37:1e:23:fe:52: 48 | 63:fc:61:79:81:1f:f6:20:93:62:8b:6b:90:f9:eb:76:a1:d5: 49 | dd:2a:f1:f7:ca:71:fd:32:50:d0:53:1b:b3:07:43:db:12:3b: 50 | a1:bd:28:44:4b:fb:8a:c9:8f:ac:17:df:67:10:32:ad:c0:f2: 51 | e7:1c:b8:f6:9c:c2:b5:2f:ea:b3:e6:3c:ff:6c:fd:a9:07:b8: 52 | cf:f0:f9:61:0a:40:2c:36:c2:2e:62:b9:8c:c0:52:89:05:2b: 53 | ff:7b:39:e9:65:b3:fd:5b:3a:8e:a1:54:9d:39:3e:10:c7:24: 54 | ff:df:f7:4a:39:41:5d:0e:5d:96:4f:0d:2f:fd:8d:51:65:dd: 55 | a4:4c:d5:f4:64:f9:aa:9c:20:47:0a:1e:44:e3:4e:a5:44:eb: 56 | f3:ab:9f:83:7e:c9:8c:81:58:8e:48:4d:d6:5c:f9:5a:ff:bb: 57 | 11:4c:4a:9f:7f:4d:fb:cd:f0:4a:44:6f:89:56:1a:86:ad:c7: 58 | 8d:0d:d9:bb:36:37:d5:a2:ca:6c:1e:a4:36:a8:c0:dd:df:82: 59 | b2:7c:8b:7b:c9:a0:06:5d:b7:34:61:67:1c:a2:ec:d5:c6:f3: 60 | 73:9b:ba:f5:e5:7b:e1:57:cf:12:1c:d6:91:82:30:2f:52:6f: 61 | d1:8b:17:8c 62 | -----BEGIN CERTIFICATE----- 63 | MIIEvjCCA6agAwIBAgIBAjANBgkqhkiG9w0BAQQFADCBkzELMAkGA1UEBhMCRlIx 64 | DjAMBgNVBAgTBVBhcmlzMQ4wDAYDVQQHEwVQYXJpczEQMA4GA1UEChMHYWtpbmFy 65 | dTEQMA4GA1UECxMHYWtpbmFydTEYMBYGA1UEAxMPV2Vic29ja2V0U2VydmVyMSYw 66 | JAYJKoZIhvcNAQkBFhdraXJ1YXpvbGRpazkyQGdtYWlsLmNvbTAeFw0xNTA1MTYw 67 | MjUxNDJaFw0yNTA1MTMwMjUxNDJaMIGFMQswCQYDVQQGEwJGUjEOMAwGA1UECBMF 68 | UGFyaXMxEDAOBgNVBAoTB2FraW5hcnUxEDAOBgNVBAsTB2FraW5hcnUxGjAYBgNV 69 | BAMTEXdlYnNvY2tldC1jbGllbnQxMSYwJAYJKoZIhvcNAQkBFhdraXJ1YXpvbGRp 70 | azkyQGdtYWlsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANRe 71 | t63uiOtDsc0LkopIq+1/L77Ru+55pw0eFBtA0cVRwIqNDrgMWxkVL+PuJKWPqgSi 72 | O4uNPy8NG5X89R9/JlVMsNZ01HufjqGrUmtZVTPnFcavixrdVPw3Coetb19xNpwd 73 | q8C5b1602TVp7kTdg75QjYj6LJPWpAB/Fo3ROdpIdw7LtB0uiKVe513HiN0G9gCO 74 | +63kYukOaJlXA+tKIBzEps7vVtrj+6TD8AScaLi3B5ikKexo/0bWbxTK2VOeZrrV 75 | 7drkAGyc9Fmbt+FAQAnf43pU/1ZyclUQLKEAYjp+wJzQs0uKRLdTL9GbO42UM8aN 76 | OBy/HL5i+1Qkz5XyMZsCAwEAAaOCAScwggEjMAkGA1UdEwQCMAAwLAYJYIZIAYb4 77 | QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBSf 78 | AErr9eI+QsT8GyvRpOOsZeBWCTCByAYDVR0jBIHAMIG9gBQBS4D3UNneFQNQeJe8 79 | ZEt/ZCoisKGBmaSBljCBkzELMAkGA1UEBhMCRlIxDjAMBgNVBAgTBVBhcmlzMQ4w 80 | DAYDVQQHEwVQYXJpczEQMA4GA1UEChMHYWtpbmFydTEQMA4GA1UECxMHYWtpbmFy 81 | dTEYMBYGA1UEAxMPV2Vic29ja2V0U2VydmVyMSYwJAYJKoZIhvcNAQkBFhdraXJ1 82 | YXpvbGRpazkyQGdtYWlsLmNvbYIJAKpq46muqS1dMA0GCSqGSIb3DQEBBAUAA4IB 83 | AQAZm5Kp2bdnbEXFBt6kNx4j/lJj/GF5gR/2IJNii2uQ+et2odXdKvH3ynH9MlDQ 84 | UxuzB0PbEjuhvShES/uKyY+sF99nEDKtwPLnHLj2nMK1L+qz5jz/bP2pB7jP8Plh 85 | CkAsNsIuYrmMwFKJBSv/eznpZbP9WzqOoVSdOT4QxyT/3/dKOUFdDl2WTw0v/Y1R 86 | Zd2kTNX0ZPmqnCBHCh5E406lROvzq5+DfsmMgViOSE3WXPla/7sRTEqff037zfBK 87 | RG+JVhqGrceNDdm7NjfVospsHqQ2qMDd34KyfIt7yaAGXbc0YWccouzVxvNzm7r1 88 | 5XvhV88SHNaRgjAvUm/RixeM 89 | -----END CERTIFICATE----- 90 | -------------------------------------------------------------------------------- /certs/client/client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDUXret7ojrQ7HN 3 | C5KKSKvtfy++0bvueacNHhQbQNHFUcCKjQ64DFsZFS/j7iSlj6oEojuLjT8vDRuV 4 | /PUffyZVTLDWdNR7n46hq1JrWVUz5xXGr4sa3VT8NwqHrW9fcTacHavAuW9etNk1 5 | ae5E3YO+UI2I+iyT1qQAfxaN0TnaSHcOy7QdLoilXuddx4jdBvYAjvut5GLpDmiZ 6 | VwPrSiAcxKbO71ba4/ukw/AEnGi4tweYpCnsaP9G1m8UytlTnma61e3a5ABsnPRZ 7 | m7fhQEAJ3+N6VP9WcnJVECyhAGI6fsCc0LNLikS3Uy/RmzuNlDPGjTgcvxy+YvtU 8 | JM+V8jGbAgMBAAECggEASprnrguhP/ztBlptZXT4KRvIOyHVAobsH5iUeaqAxu/c 9 | UxAQvqlgi2Q9CbaMWzkoAi63+mNpce8J5NwThLgXUFn7uasbRj6cTcEw2BNu8ifZ 10 | J45dsNdWVrBDW7ya5o2QILHvt2mtbTjdIX2QPdMPyBjmT9uLM3hw7te2paV9zGeK 11 | teCft/ZlUTDNvwYlt7XIczK1GxFcxbwCgfbZyXyIo2V+H4if9jba0RQ06MIaGBmm 12 | m2s8GWSNhlMdpr40TnxT9r4pW0fKBqXHF0yLG8KTSBBDCqgHNmNiCQ7KoZVidzM+ 13 | K1vNdEHJ19XzWkmEHyJAI9+znoWCLbfTrgaw6Qu22QKBgQDxqIX2WSg9CpPl+Ih7 14 | 1XR9W+fFRXpdy0+AoT6dUUKrkYydL7ScHxa355YEkX4DiiOjYFaPrfyMEtkIz6I8 15 | vI5RoWleRDNiH8ai14/R0hkNQBqsJ/dnusa0IH+VKKrSHdKLpB2/7vHXWxh0DSdJ 16 | QAljDEeo8WHn5io3P+9/W1LePQKBgQDg+Ti5nJgfPkG3SYQSRLNZa5v9YSAzXD/0 17 | R0tRo1UZnF/iKMRb2rF8+2FsrcMKY/Zg/ptU9qnXNil/vCXl5F5NQx6/L31r75fA 18 | vql0cEuDfCx64jRL6g4wTo11oTscCsYZhbbpQ8Nm+IkzTCHb8iModSfjLziYBsGK 19 | SyIwWlPktwKBgQDHB10Nv/B8FbIpvb/q/aqrdH424zoc9c3MywCe4MZgN8fvzdKa 20 | oqA7ZukPaiS3FZa0gCvKuik91Ggb8aZVD5bHdIEruk/3iOQ4SgGRddBcMWfGUkRZ 21 | kmMFB58MYioOU7GMgOZfpZRZIhXJvuuUUMFqajq60dMpA0/RoT7HTZe6oQKBgCeb 22 | eOMksJt/iG5OYRQeSD0L9vCK8vJX4WKOUrJSwR67Kx5T8w4A2JKaZzKM/PONWckF 23 | yi8RJiGfhXrZkwqARCHyGS2rnLct/VePuaGoS4Mgj2wq+u4KjOjwS3NUKWXsd6fy 24 | pJs4tOQiCXWgh62DWbE7vwP+QkZxmg1Q4PoGTRLNAoGBAK7YLGe181K/pUobaL4j 25 | keKr1T8/Fhwcr3MeKLQiLX9VJNGPeaxg5RyLAXii2GY3JpIt4CMC8MfXzYup18ux 26 | GjGfFZgkUjThKiVRkvcEaiU/uAf93gSxQJQfWBwICGTCHsBK4WmMo66T8AnqDFaR 27 | Ycp0ifzenixobqox1EgylTSO 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /certs/client/client.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bertrandmartel/digest-auth-session-cpp/HEAD/certs/client/client.p12 -------------------------------------------------------------------------------- /certs/server/server.crt: -------------------------------------------------------------------------------- 1 | Certificate: 2 | Data: 3 | Version: 3 (0x2) 4 | Serial Number: 1 (0x1) 5 | Signature Algorithm: md5WithRSAEncryption 6 | Issuer: C=FR, ST=Paris, L=Paris, O=akinaru, OU=akinaru, CN=WebsocketServer/emailAddress=bmartel.fr@gmail.com 7 | Validity 8 | Not Before: May 16 02:50:46 2015 GMT 9 | Not After : May 13 02:50:46 2025 GMT 10 | Subject: C=FR, ST=Paris, O=akinaru, OU=akinaru, CN=websocket-main-server/emailAddress=bmartel.fr@gmail.com 11 | Subject Public Key Info: 12 | Public Key Algorithm: rsaEncryption 13 | Public-Key: (2048 bit) 14 | Modulus: 15 | 00:cd:c5:7b:d4:38:97:73:78:24:7b:b0:31:de:09: 16 | f7:69:a6:67:47:76:d5:a3:6e:af:02:ed:d7:78:a8: 17 | 81:78:43:6e:36:d1:38:76:1b:d3:9f:ae:5f:6d:a2: 18 | d1:76:a4:13:7d:88:22:57:21:b8:f2:1c:a2:13:7c: 19 | b9:8f:d4:5a:13:a5:f3:9b:e0:a7:31:cd:2f:bb:e4: 20 | 97:f5:a5:c6:32:ec:53:26:68:03:a7:c8:90:42:3c: 21 | 38:47:5f:cd:73:95:5c:10:f5:8b:b7:30:b2:eb:64: 22 | 25:5e:42:0f:e5:19:31:f1:73:2a:77:a8:47:40:75: 23 | 3b:c9:db:20:f9:0e:37:5f:6d:af:2d:7c:94:dc:4a: 24 | 99:98:a0:8c:bd:42:8d:5d:cf:e5:78:3b:9e:79:c4: 25 | 1a:24:b8:66:7d:b5:21:62:38:ed:db:0e:48:dc:a4: 26 | 63:5c:97:38:3f:1b:55:e4:52:85:d0:ce:6c:a4:75: 27 | ad:12:21:29:8c:8b:80:98:ae:78:ae:cc:30:bd:cc: 28 | 76:a7:03:49:b0:ad:b0:f4:d1:83:a2:17:4c:40:19: 29 | 1e:11:70:d0:44:36:12:2b:b7:bf:36:72:12:31:42: 30 | 63:eb:fc:c4:2d:3c:f7:61:c5:ec:9d:f2:4b:74:9d: 31 | 71:e0:05:99:ec:e5:0c:6c:91:78:9a:05:88:2e:f8: 32 | dc:31 33 | Exponent: 65537 (0x10001) 34 | X509v3 extensions: 35 | X509v3 Basic Constraints: 36 | CA:FALSE 37 | Netscape Cert Type: 38 | SSL Server 39 | Netscape Comment: 40 | OpenSSL Generated Server Certificate 41 | X509v3 Subject Key Identifier: 42 | 65:85:D3:97:31:24:14:E0:0B:55:9C:61:D6:92:F4:AE:7E:41:03:C1 43 | X509v3 Authority Key Identifier: 44 | keyid:01:4B:80:F7:50:D9:DE:15:03:50:78:97:BC:64:4B:7F:64:2A:22:B0 45 | DirName:/C=FR/ST=Paris/L=Paris/O=akinaru/OU=akinaru/CN=WebsocketServer/emailAddress=bmartel.fr@gmail.com 46 | serial:AA:6A:E3:A9:AE:A9:2D:5D 47 | 48 | Signature Algorithm: md5WithRSAEncryption 49 | 2e:a5:d5:35:b9:1a:83:3b:8b:55:03:3d:f4:40:06:e6:34:8f: 50 | 73:96:02:3a:0c:40:05:f0:1d:3b:66:2c:2c:1d:ad:54:9f:01: 51 | da:ae:17:d1:52:c8:41:f1:61:fb:d3:fa:8d:ac:94:52:75:6e: 52 | 3a:77:54:3c:b2:f3:fe:cc:19:e9:2b:b3:b1:fc:29:10:90:36: 53 | 9c:64:75:09:70:f5:41:b2:e6:c3:42:02:6d:f1:6f:66:ca:41: 54 | fd:11:58:dd:58:ac:a2:87:0d:e5:8c:67:b4:62:97:40:6b:f8: 55 | fb:6e:be:bd:7b:1d:bd:ec:91:d9:65:38:ed:1c:04:ef:ef:41: 56 | 11:9c:90:5c:86:5a:b0:e7:c1:58:03:aa:6b:fb:c4:c5:3f:85: 57 | ca:c3:18:39:8f:86:90:da:bd:8b:19:7f:31:32:88:bf:3a:b5: 58 | 29:ab:ab:c7:8a:ef:b5:27:de:bf:f1:29:44:01:91:c3:ac:d8: 59 | 57:1a:d2:6e:30:98:db:59:33:f5:cf:31:20:e0:b3:75:9c:0c: 60 | 1e:18:16:46:d7:16:d1:ad:c9:a0:25:e8:07:b7:78:b9:1a:43: 61 | 66:f3:37:f1:26:a4:56:6d:a7:e1:24:bd:51:af:d5:d0:65:07: 62 | 36:58:8e:57:4d:ef:20:d3:02:62:76:4d:d6:64:5f:94:a6:9d: 63 | 34:0b:37:47 64 | -----BEGIN CERTIFICATE----- 65 | MIIE3DCCA8SgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBkzELMAkGA1UEBhMCRlIx 66 | DjAMBgNVBAgTBVBhcmlzMQ4wDAYDVQQHEwVQYXJpczEQMA4GA1UEChMHYWtpbmFy 67 | dTEQMA4GA1UECxMHYWtpbmFydTEYMBYGA1UEAxMPV2Vic29ja2V0U2VydmVyMSYw 68 | JAYJKoZIhvcNAQkBFhdraXJ1YXpvbGRpazkyQGdtYWlsLmNvbTAeFw0xNTA1MTYw 69 | MjUwNDZaFw0yNTA1MTMwMjUwNDZaMIGJMQswCQYDVQQGEwJGUjEOMAwGA1UECBMF 70 | UGFyaXMxEDAOBgNVBAoTB2FraW5hcnUxEDAOBgNVBAsTB2FraW5hcnUxHjAcBgNV 71 | BAMTFXdlYnNvY2tldC1tYWluLXNlcnZlcjEmMCQGCSqGSIb3DQEJARYXa2lydWF6 72 | b2xkaWs5MkBnbWFpbC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB 73 | AQDNxXvUOJdzeCR7sDHeCfdppmdHdtWjbq8C7dd4qIF4Q2420Th2G9Ofrl9totF2 74 | pBN9iCJXIbjyHKITfLmP1FoTpfOb4KcxzS+75Jf1pcYy7FMmaAOnyJBCPDhHX81z 75 | lVwQ9Yu3MLLrZCVeQg/lGTHxcyp3qEdAdTvJ2yD5Djdfba8tfJTcSpmYoIy9Qo1d 76 | z+V4O555xBokuGZ9tSFiOO3bDkjcpGNclzg/G1XkUoXQzmykda0SISmMi4CYrniu 77 | zDC9zHanA0mwrbD00YOiF0xAGR4RcNBENhIrt782chIxQmPr/MQtPPdhxeyd8kt0 78 | nXHgBZns5QxskXiaBYgu+NwxAgMBAAGjggFBMIIBPTAJBgNVHRMEAjAAMBEGCWCG 79 | SAGG+EIBAQQEAwIGQDAzBglghkgBhvhCAQ0EJhYkT3BlblNTTCBHZW5lcmF0ZWQg 80 | U2VydmVyIENlcnRpZmljYXRlMB0GA1UdDgQWBBRlhdOXMSQU4AtVnGHWkvSufkED 81 | wTCByAYDVR0jBIHAMIG9gBQBS4D3UNneFQNQeJe8ZEt/ZCoisKGBmaSBljCBkzEL 82 | MAkGA1UEBhMCRlIxDjAMBgNVBAgTBVBhcmlzMQ4wDAYDVQQHEwVQYXJpczEQMA4G 83 | A1UEChMHYWtpbmFydTEQMA4GA1UECxMHYWtpbmFydTEYMBYGA1UEAxMPV2Vic29j 84 | a2V0U2VydmVyMSYwJAYJKoZIhvcNAQkBFhdraXJ1YXpvbGRpazkyQGdtYWlsLmNv 85 | bYIJAKpq46muqS1dMA0GCSqGSIb3DQEBBAUAA4IBAQAupdU1uRqDO4tVAz30QAbm 86 | NI9zlgI6DEAF8B07ZiwsHa1UnwHarhfRUshB8WH70/qNrJRSdW46d1Q8svP+zBnp 87 | K7Ox/CkQkDacZHUJcPVBsubDQgJt8W9mykH9EVjdWKyihw3ljGe0YpdAa/j7br69 88 | ex297JHZZTjtHATv70ERnJBchlqw58FYA6pr+8TFP4XKwxg5j4aQ2r2LGX8xMoi/ 89 | OrUpq6vHiu+1J96/8SlEAZHDrNhXGtJuMJjbWTP1zzEg4LN1nAweGBZG1xbRrcmg 90 | JegHt3i5GkNm8zfxJqRWbafhJL1Rr9XQZQc2WI5XTe8g0wJidk3WZF+Upp00CzdH 91 | -----END CERTIFICATE----- 92 | -------------------------------------------------------------------------------- /certs/server/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDNxXvUOJdzeCR7 3 | sDHeCfdppmdHdtWjbq8C7dd4qIF4Q2420Th2G9Ofrl9totF2pBN9iCJXIbjyHKIT 4 | fLmP1FoTpfOb4KcxzS+75Jf1pcYy7FMmaAOnyJBCPDhHX81zlVwQ9Yu3MLLrZCVe 5 | Qg/lGTHxcyp3qEdAdTvJ2yD5Djdfba8tfJTcSpmYoIy9Qo1dz+V4O555xBokuGZ9 6 | tSFiOO3bDkjcpGNclzg/G1XkUoXQzmykda0SISmMi4CYrniuzDC9zHanA0mwrbD0 7 | 0YOiF0xAGR4RcNBENhIrt782chIxQmPr/MQtPPdhxeyd8kt0nXHgBZns5QxskXia 8 | BYgu+NwxAgMBAAECggEAM+9dIqIp75XqN2GwJGeFj5/VP19J6pb8CxQ2pxh4nP7/ 9 | 6UwDISRC1HGxWj2W+ofM94kNicpUIJ+DdMGtIBUrqvvesYAREuvD2XuHsxNlI+Mr 10 | 1Wy5R3bCmkUSu0j91Odktk8TNWhQMEM1f0XTNzKVvWgg1tSdLzKnpXnuJ44kAax7 11 | 7CU0Dq/c6jNNqrNy9rEDRj4URDyP/DgpER3XogLQ03zjg31rlVFP06TAeN2MVJjx 12 | D0KkbtWNPOAiEobwlB3Qt9RDN1zIkkkPBHncE0aNFyjVO2UPKvyDKAiAv6Fuf2bn 13 | PsP45LMSZBraq+h15SyL6fEKdQjIll5d4gBqcpe8sQKBgQD+Q5yRyd0e/unBxZTK 14 | XaHZOUFUFQ1sslwHoVtmZnAp8WPLpr/IQOcpdclLB5HpU7FymGVw9dpCwK8s4F3y 15 | kUX6dmRjcT417rp3Q5UYQxus2e34GA624sTsuLHQuu96jrKVkxGvqq5Gvvc1TQQ4 16 | XmkH6pocBgmK0LCnM1rB0aX3jQKBgQDPLR6M2OL0A54gAwlvdJCiiUadIH612pwN 17 | ftd7gBpgXKmHjv5Ly02rkOYjGtBJQLgLBZ0/akOme+r0DF5H8c/eQMRwcov8E8QA 18 | U9ISDYzhmO7sJlKw7X7bPt86TPwBSBA0xvg9lxhyVuvkorTwCaV0ThYpoUk2AL2S 19 | 2qEcRooMNQKBgDz6MAFSnQIC9kJvRPinLdpvfbhReC+6MpHt44KSTJHyfxFnAxVe 20 | Y1GxGr4wqZCAbszhuWo2u8pIdXpYsI8swdCINhkXHmlGwFc70PTJm0h/1y8pbdX0 21 | Wm++933sZuRIdpGifJpZX4Q95gFVYA64rY2leKIB3KX62HKwwTI8OgY9AoGBAI/q 22 | Ar/KZZUl8jDAi0xeB56wh1nc2chPrHl/dAY5TZlEpQsinKlf93tHc2ZNWQSZrX8S 23 | jlIf6hB7IhIXiWKmqkP0b8DBAVbBEDU+BL4/pW6NAuMOGAEJaUa5nO1tztzBB2jy 24 | Ej0OeY/rq3+uOsxHlyR8nc6bWDToPMgHkUUIBxtFAoGBAN7VwFVsH3F80Rb9E0tt 25 | jtg9SnFs4SozNsl7VEKJ9wglmz/Swi9e8UpBakYKesxXjwWaYoYDSAnx8aqn1B8j 26 | myG2JT09xqJIPFOnHqFE6X296i2Dji1Fqjh4JlQCbaEHysNDg0qoFl+6kHA+AvKr 27 | rXh71I4w46HTW+0g7PXCkJyV 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /digest-auth-session-lib/DigestManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | DigestManager.h 26 | Client socket managing event handler 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef DIGESTMANAGER_H 32 | #define DIGESTMANAGER_H 33 | 34 | #include "Digestinfo.h" 35 | #include "QList" 36 | #include "digeststruct.h" 37 | #include "IDigestListener.h" 38 | #include "QDateTime" 39 | #include "map" 40 | 41 | /* nonce structure used to store stateful data about nonce creation / lifetime */ 42 | typedef struct { 43 | std::string nonce; // nonce value 44 | unsigned long expiring_date; // expiring date in millisecond since 1970 45 | unsigned int nonce_count; // nonce server count 46 | bool stale; // true if former nonce was rejected due to expiration (NOT IMPLEMENTED FOR NOW) 47 | std::string session_id; // session id (only for COOKIE session type => this must match an entry in session structure below for this type of session) 48 | } nonce; 49 | 50 | /* session structure used to store stateful data about session entry for COOKIE session type*/ 51 | typedef struct{ 52 | QDateTime session_start_date; // session record date 53 | bool validity; // validity of session entry 54 | } session; 55 | 56 | /** 57 | * @brief The DigestManager class 58 | * Client socket managing event handler 59 | */ 60 | class DigestManager{ 61 | 62 | public: 63 | 64 | /** 65 | * @brief DigestManager 66 | * build client socket handler 67 | */ 68 | DigestManager(); 69 | 70 | ~DigestManager(); 71 | 72 | /** 73 | * @brief process_digest 74 | * process digest request / response according to method / uri / headers given in parameters.
75 | * Will return following http content body according digest processing : 76 | * 81 | * @param method 82 | * http method 83 | * @param uri 84 | * http uri 85 | * @param headers 86 | * http headers 87 | * @param realm 88 | * chosen realm for given uri 89 | * @return 90 | * DigestInfo 91 | */ 92 | DigestInfo process_digest(std::string method,std::string uri,std::map headers,std::string realm); 93 | 94 | /** 95 | * @brief DigestManager::remove_expired_nonces 96 | * Remove all nonces in map that expired 97 | */ 98 | void remove_expired_nonces(); 99 | 100 | /** 101 | * @brief DigestManager::remove_expired_sessions 102 | * Remove all session in map that expired 103 | */ 104 | void remove_expired_sessions(); 105 | 106 | /** 107 | * @brief getAuthenticationCookieField 108 | * Retrieve HSID value from cookie http header 109 | * 110 | * @param cookieStr 111 | * cookie header value 112 | * @return 113 | */ 114 | std::string getAuthenticationCookieField(std::string cookieStr); 115 | 116 | /** 117 | * @brief splitHeader 118 | * @param header 119 | * @param delim 120 | * @return 121 | */ 122 | std::map splitHeader(std::string header,char delim); 123 | 124 | /** 125 | * @brief remove_session_for_headers 126 | * Remove a session (cookie or digest) 127 | * @param headers 128 | * @return 129 | */ 130 | int remove_session_for_headers(std::map *headers); 131 | 132 | /** 133 | * @brief DigestManager::generateHandshakeProcess 134 | * build digest authentication request 135 | * @param host 136 | * host address 137 | * @param path_realm 138 | * realm used for authentication 139 | * @return 140 | * DigestInfo 141 | */ 142 | DigestInfo generateHandshakeProcess(std::string host,std::string realm); 143 | 144 | /** 145 | * @brief DigestManager::generateRandomNum 146 | * Generate random alpha numeric string 147 | * @param num 148 | * length of random string 149 | * @return 150 | */ 151 | std::string generateRandomNum(unsigned int num); 152 | 153 | /** 154 | * @brief DigestManager::processDigestResponse 155 | * Process digest response request to authenticate and validate session cookie 156 | * 157 | * @param authorizationHeader 158 | * header Authorization 159 | * @param cookieHeader 160 | * Cookie header 161 | * @param realm 162 | * realm used for this authentication 163 | * @param http_method_requested 164 | * http method requested by client 165 | * @param uri_requested 166 | * uri requested by client 167 | * @return 168 | * DigestInfo 169 | */ 170 | DigestInfo processDigestResponse(std::string authorizationHeader,std::string cookieHeader,std::string realm,std::string http_method_requested,std::string uri_requested); 171 | 172 | /** 173 | * @brief DigestManager::set_show_algorithm 174 | * algorithm used in digest authentication will be sent to client if set to true (default) 175 | * @param show_in_response 176 | */ 177 | void set_show_algorithm(bool show_in_response); 178 | 179 | /** 180 | * @brief DigestManager::set_digest_algorithm 181 | * Set digest algorithm used for processing hash 182 | * @param algorithm 183 | */ 184 | void set_digest_algorithm(digest_algorithm algorithm); 185 | 186 | /** 187 | * @brief DigestManager::getAlgorithm 188 | * Retrieve digest get_algorithm used for processing hash 189 | * @return 190 | */ 191 | digest_algorithm get_algorithm(); 192 | 193 | /** 194 | * @brief DigestManager::set_nonce_timeout_millis 195 | * set nonce timeout in milliseconds 196 | * @param nonce_timeout 197 | */ 198 | void set_nonce_timeout_millis(long nonce_timeout); 199 | 200 | /** 201 | * @brief DigestManager::get_nonce_timeout_millis 202 | * Retrieve nonce timeout in milliseconds 203 | * @return 204 | */ 205 | long get_nonce_timeout_millis(); 206 | 207 | /** 208 | * @brief DigestManager::set_digest_listener 209 | * Set digest listener 210 | * @param digest_listener 211 | */ 212 | void set_digest_listener(IDigestListener* digest_listener); 213 | 214 | /** 215 | * @brief DigestManager::set_session_type 216 | * Set session type (default is DIGEST session) 217 | * @param session 218 | */ 219 | void set_session_type(session_type session); 220 | 221 | /** 222 | * @brief DigestManager::get_session_type 223 | * Retrieve session type 224 | * @return 225 | */ 226 | session_type get_session_type(); 227 | 228 | /** 229 | * @brief DigestManager::set_max_session_time 230 | * Set maximum session time for user 231 | * @param session_time 232 | */ 233 | void set_max_session_time(int session_time); 234 | 235 | /** 236 | * @brief DigestManager::get_max_session_time 237 | * Retrieve maximum session time for user 238 | * @return 239 | */ 240 | int get_max_session_time(); 241 | 242 | /** 243 | * @brief show_algorithm 244 | * if set to true will show algorithm used in response to client 245 | */ 246 | bool show_algorithm; 247 | 248 | /** 249 | * @brief algorithm 250 | * algorithm used to compute hashes 251 | */ 252 | digest_algorithm algorithm; 253 | 254 | /** 255 | * @brief nonce_timeout_millis 256 | * nonce timeout in milliseconds (it is the session duration when digest session is used) 257 | */ 258 | long nonce_timeout_millis; 259 | 260 | /** 261 | * @brief digest_listener 262 | * listener for retrievinf username / password hash from storage 263 | */ 264 | IDigestListener * digest_listener; 265 | 266 | /** 267 | * @brief session_t 268 | * type of session used (can be DIGEST or COOKIE) 269 | */ 270 | session_type session_t; 271 | 272 | /** 273 | * @brief session_time_seconds 274 | * session duration for COOKIE session type (DIGEST session duration is set by nonce timeout) 275 | */ 276 | int session_time_seconds; 277 | 278 | /** 279 | * @brief nonce_map 280 | * map of nonces 281 | */ 282 | std::map< std::string, nonce> nonce_map; 283 | 284 | /** 285 | * @brief session_map 286 | * map of sessions (used only for COOKIE session) 287 | */ 288 | std::map< std::string, session> session_map; 289 | }; 290 | 291 | #endif // DIGESTMANAGER_H 292 | -------------------------------------------------------------------------------- /digest-auth-session-lib/Digestinfo.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | DigestInfo.cpp 26 | Output digest information to be sent to client 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #include "Digestinfo.h" 32 | 33 | /** 34 | * @brief DigestInfo 35 | * @param status_code 36 | * http status code 37 | * @param headers 38 | * http headers 39 | */ 40 | DigestInfo::DigestInfo(int status_code,std::map< std::string,std::string> headers){ 41 | this->status_code=status_code; 42 | this->headers=headers; 43 | } 44 | 45 | DigestInfo::~DigestInfo() 46 | { 47 | } 48 | 49 | /** 50 | * @brief get_status_code 51 | * Retrieve status code to return 52 | * @return 53 | */ 54 | 55 | int DigestInfo::get_status_code(){ 56 | return status_code; 57 | } 58 | 59 | 60 | /** 61 | * @brief get_headers 62 | * Retrieve headers to return 63 | * @return 64 | */ 65 | 66 | std::map< std::string,std::string > *DigestInfo::get_headers(){ 67 | return &headers; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /digest-auth-session-lib/Digestinfo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | DigestInfo.h 26 | Output digest information to be sent to client 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef DIGESTINFO_H 32 | #define DIGESTINFO_H 33 | 34 | #include "map" 35 | #include "string" 36 | 37 | /** 38 | * @brief The DigestInfo class 39 | * Digest information used to build http request/response 40 | */ 41 | class DigestInfo 42 | { 43 | public: 44 | 45 | /** 46 | * @brief DigestInfo 47 | * @param status_code 48 | * http status code 49 | * @param headers 50 | * http headers 51 | */ 52 | DigestInfo(int status_code,std::map< std::string,std::string> headers); 53 | 54 | ~DigestInfo(); 55 | 56 | /** 57 | * @brief get_status_code 58 | * Retrieve status code to return 59 | * @return 60 | */ 61 | int get_status_code(); 62 | 63 | /** 64 | * @brief get_headers 65 | * Retrieve headers to return 66 | * @return 67 | */ 68 | std::map< std::string,std::string >* get_headers(); 69 | 70 | private: 71 | 72 | /** 73 | * @brief status_code 74 | * http status code 75 | */ 76 | int status_code; 77 | 78 | /** 79 | * @brief headers 80 | * http headers 81 | */ 82 | std::map< std::string,std::string > headers; 83 | }; 84 | 85 | #endif // DIGESTINFO_H 86 | -------------------------------------------------------------------------------- /digest-auth-session-lib/IDigestListener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IDigestListener.h 26 | 27 | Generic interface for digest listener. Used to implement a listener to retrieve username / password hashe from storage 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef IDIGESTLISTENER_H 33 | #define IDIGESTLISTENER_H 34 | 35 | #include "string" 36 | #include "digeststruct.h" 37 | 38 | class IDigestListener{ 39 | 40 | public: 41 | 42 | /** 43 | * @brief getUri 44 | * retrieve HTTP uri 45 | * @return 46 | */ 47 | virtual std::string get_hash_for_username(std::string username,std::string realm,digest_algorithm algo)=0; 48 | }; 49 | 50 | #endif // IDIGESTLISTENER_H 51 | -------------------------------------------------------------------------------- /digest-auth-session-lib/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Makefile for building: libdigestauthsession.a 3 | # Generated by qmake (2.01a) (Qt 4.8.4) on: Sat Oct 10 20:32:36 2015 4 | # Project: digest-auth-session.pro 5 | # Template: lib 6 | # Command: /usr/lib/i386-linux-gnu/qt4/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile digest-auth-session.pro 7 | ############################################################################# 8 | 9 | ####### Compiler, tools and options 10 | 11 | CC = gcc 12 | CXX = g++ 13 | DEFINES = -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED 14 | CFLAGS = -pipe -g -fPIC -Wall -W -D_REENTRANT $(DEFINES) 15 | CXXFLAGS = -pipe -std=c++0x -g -fPIC -Wall -W -D_REENTRANT $(DEFINES) 16 | INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -Ilibs -I. 17 | AR = ar cqs 18 | RANLIB = 19 | QMAKE = /usr/lib/i386-linux-gnu/qt4/bin/qmake 20 | TAR = tar -cf 21 | COMPRESS = gzip -9f 22 | COPY = cp -f 23 | SED = sed 24 | COPY_FILE = $(COPY) 25 | COPY_DIR = $(COPY) -r 26 | STRIP = strip 27 | INSTALL_FILE = install -m 644 -p 28 | INSTALL_DIR = $(COPY_DIR) 29 | INSTALL_PROGRAM = install -m 755 -p 30 | DEL_FILE = rm -f 31 | SYMLINK = ln -f -s 32 | DEL_DIR = rmdir 33 | MOVE = mv -f 34 | CHK_DIR_EXISTS= test -d 35 | MKDIR = mkdir -p 36 | 37 | ####### Output directory 38 | 39 | OBJECTS_DIR = bin/ 40 | 41 | ####### Files 42 | 43 | SOURCES = utils/stringutil.cpp \ 44 | DigestManager.cpp \ 45 | Digestinfo.cpp 46 | OBJECTS = bin/stringutil.o \ 47 | bin/DigestManager.o \ 48 | bin/Digestinfo.o 49 | DIST = /usr/share/qt4/mkspecs/common/unix.conf \ 50 | /usr/share/qt4/mkspecs/common/linux.conf \ 51 | /usr/share/qt4/mkspecs/common/gcc-base.conf \ 52 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ 53 | /usr/share/qt4/mkspecs/common/g++-base.conf \ 54 | /usr/share/qt4/mkspecs/common/g++-unix.conf \ 55 | /usr/share/qt4/mkspecs/qconfig.pri \ 56 | /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ 57 | /usr/share/qt4/mkspecs/features/qt_functions.prf \ 58 | /usr/share/qt4/mkspecs/features/qt_config.prf \ 59 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 60 | /usr/share/qt4/mkspecs/features/default_pre.prf \ 61 | /usr/share/qt4/mkspecs/features/debug.prf \ 62 | /usr/share/qt4/mkspecs/features/default_post.prf \ 63 | /usr/share/qt4/mkspecs/features/staticlib.prf \ 64 | /usr/share/qt4/mkspecs/features/static.prf \ 65 | /usr/share/qt4/mkspecs/features/declarative_debug.prf \ 66 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ 67 | /usr/share/qt4/mkspecs/features/warn_on.prf \ 68 | /usr/share/qt4/mkspecs/features/qt.prf \ 69 | /usr/share/qt4/mkspecs/features/unix/thread.prf \ 70 | /usr/share/qt4/mkspecs/features/moc.prf \ 71 | /usr/share/qt4/mkspecs/features/resources.prf \ 72 | /usr/share/qt4/mkspecs/features/uic.prf \ 73 | /usr/share/qt4/mkspecs/features/yacc.prf \ 74 | /usr/share/qt4/mkspecs/features/lex.prf \ 75 | /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 76 | digest-auth-session.pro 77 | QMAKE_TARGET = digestauthsession 78 | DESTDIR = release/ 79 | TARGET = libdigestauthsession.a 80 | 81 | first: all 82 | ####### Implicit rules 83 | 84 | .SUFFIXES: .o .c .cpp .cc .cxx .C 85 | 86 | .cpp.o: 87 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 88 | 89 | .cc.o: 90 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 91 | 92 | .cxx.o: 93 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 94 | 95 | .C.o: 96 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 97 | 98 | .c.o: 99 | $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" 100 | 101 | ####### Build rules 102 | 103 | all: Makefile release/$(TARGET) 104 | 105 | staticlib: release/$(TARGET) 106 | 107 | release/$(TARGET): $(OBJECTS) $(OBJCOMP) 108 | @$(CHK_DIR_EXISTS) release/ || $(MKDIR) release/ 109 | -$(DEL_FILE) $(TARGET) 110 | $(AR) $(TARGET) $(OBJECTS) 111 | rsync -avm --include=*/ --include=*.h --exclude=* /home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-lib// /home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-lib/release 112 | -$(DEL_FILE) release/$(TARGET) 113 | -$(MOVE) $(TARGET) release/ 114 | 115 | 116 | Makefile: digest-auth-session.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ 117 | /usr/share/qt4/mkspecs/common/linux.conf \ 118 | /usr/share/qt4/mkspecs/common/gcc-base.conf \ 119 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ 120 | /usr/share/qt4/mkspecs/common/g++-base.conf \ 121 | /usr/share/qt4/mkspecs/common/g++-unix.conf \ 122 | /usr/share/qt4/mkspecs/qconfig.pri \ 123 | /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ 124 | /usr/share/qt4/mkspecs/features/qt_functions.prf \ 125 | /usr/share/qt4/mkspecs/features/qt_config.prf \ 126 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 127 | /usr/share/qt4/mkspecs/features/default_pre.prf \ 128 | /usr/share/qt4/mkspecs/features/debug.prf \ 129 | /usr/share/qt4/mkspecs/features/default_post.prf \ 130 | /usr/share/qt4/mkspecs/features/staticlib.prf \ 131 | /usr/share/qt4/mkspecs/features/static.prf \ 132 | /usr/share/qt4/mkspecs/features/declarative_debug.prf \ 133 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ 134 | /usr/share/qt4/mkspecs/features/warn_on.prf \ 135 | /usr/share/qt4/mkspecs/features/qt.prf \ 136 | /usr/share/qt4/mkspecs/features/unix/thread.prf \ 137 | /usr/share/qt4/mkspecs/features/moc.prf \ 138 | /usr/share/qt4/mkspecs/features/resources.prf \ 139 | /usr/share/qt4/mkspecs/features/uic.prf \ 140 | /usr/share/qt4/mkspecs/features/yacc.prf \ 141 | /usr/share/qt4/mkspecs/features/lex.prf \ 142 | /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 143 | /usr/lib/i386-linux-gnu/libQtNetwork.prl \ 144 | /usr/lib/i386-linux-gnu/libQtCore.prl 145 | $(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile digest-auth-session.pro 146 | /usr/share/qt4/mkspecs/common/unix.conf: 147 | /usr/share/qt4/mkspecs/common/linux.conf: 148 | /usr/share/qt4/mkspecs/common/gcc-base.conf: 149 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf: 150 | /usr/share/qt4/mkspecs/common/g++-base.conf: 151 | /usr/share/qt4/mkspecs/common/g++-unix.conf: 152 | /usr/share/qt4/mkspecs/qconfig.pri: 153 | /usr/share/qt4/mkspecs/modules/qt_phonon.pri: 154 | /usr/share/qt4/mkspecs/features/qt_functions.prf: 155 | /usr/share/qt4/mkspecs/features/qt_config.prf: 156 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf: 157 | /usr/share/qt4/mkspecs/features/default_pre.prf: 158 | /usr/share/qt4/mkspecs/features/debug.prf: 159 | /usr/share/qt4/mkspecs/features/default_post.prf: 160 | /usr/share/qt4/mkspecs/features/staticlib.prf: 161 | /usr/share/qt4/mkspecs/features/static.prf: 162 | /usr/share/qt4/mkspecs/features/declarative_debug.prf: 163 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: 164 | /usr/share/qt4/mkspecs/features/warn_on.prf: 165 | /usr/share/qt4/mkspecs/features/qt.prf: 166 | /usr/share/qt4/mkspecs/features/unix/thread.prf: 167 | /usr/share/qt4/mkspecs/features/moc.prf: 168 | /usr/share/qt4/mkspecs/features/resources.prf: 169 | /usr/share/qt4/mkspecs/features/uic.prf: 170 | /usr/share/qt4/mkspecs/features/yacc.prf: 171 | /usr/share/qt4/mkspecs/features/lex.prf: 172 | /usr/share/qt4/mkspecs/features/include_source_dir.prf: 173 | /usr/lib/i386-linux-gnu/libQtNetwork.prl: 174 | /usr/lib/i386-linux-gnu/libQtCore.prl: 175 | qmake: FORCE 176 | @$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile digest-auth-session.pro 177 | 178 | dist: 179 | @$(CHK_DIR_EXISTS) bin/digestauthsession1.0.0 || $(MKDIR) bin/digestauthsession1.0.0 180 | $(COPY_FILE) --parents $(SOURCES) $(DIST) bin/digestauthsession1.0.0/ && $(COPY_FILE) --parents utils/stringutil.h IDigestListener.h digeststruct.h DigestManager.h Digestinfo.h bin/digestauthsession1.0.0/ && $(COPY_FILE) --parents utils/stringutil.cpp DigestManager.cpp Digestinfo.cpp bin/digestauthsession1.0.0/ && (cd `dirname bin/digestauthsession1.0.0` && $(TAR) digestauthsession1.0.0.tar digestauthsession1.0.0 && $(COMPRESS) digestauthsession1.0.0.tar) && $(MOVE) `dirname bin/digestauthsession1.0.0`/digestauthsession1.0.0.tar.gz . && $(DEL_FILE) -r bin/digestauthsession1.0.0 181 | 182 | 183 | clean:compiler_clean 184 | -$(DEL_FILE) $(OBJECTS) 185 | -$(DEL_FILE) -r /home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-lib/release 186 | -$(DEL_FILE) *~ core *.core 187 | 188 | 189 | ####### Sub-libraries 190 | 191 | distclean: clean 192 | -$(DEL_FILE) $(TARGET) 193 | -$(DEL_FILE) Makefile 194 | 195 | 196 | check: first 197 | 198 | mocclean: compiler_moc_header_clean compiler_moc_source_clean 199 | 200 | mocables: compiler_moc_header_make_all compiler_moc_source_make_all 201 | 202 | compiler_moc_header_make_all: 203 | compiler_moc_header_clean: 204 | compiler_rcc_make_all: 205 | compiler_rcc_clean: 206 | compiler_image_collection_make_all: qmake_image_collection.cpp 207 | compiler_image_collection_clean: 208 | -$(DEL_FILE) qmake_image_collection.cpp 209 | compiler_moc_source_make_all: 210 | compiler_moc_source_clean: 211 | compiler_uic_make_all: 212 | compiler_uic_clean: 213 | compiler_yacc_decl_make_all: 214 | compiler_yacc_decl_clean: 215 | compiler_yacc_impl_make_all: 216 | compiler_yacc_impl_clean: 217 | compiler_lex_make_all: 218 | compiler_lex_clean: 219 | compiler_clean: 220 | 221 | ####### Compile 222 | 223 | bin/stringutil.o: utils/stringutil.cpp utils/stringutil.h 224 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/stringutil.o utils/stringutil.cpp 225 | 226 | bin/DigestManager.o: DigestManager.cpp DigestManager.h \ 227 | Digestinfo.h \ 228 | digeststruct.h \ 229 | IDigestListener.h \ 230 | libs/protocol/inter/http/IhttpFrame.h \ 231 | utils/stringutil.h 232 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/DigestManager.o DigestManager.cpp 233 | 234 | bin/Digestinfo.o: Digestinfo.cpp Digestinfo.h 235 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/Digestinfo.o Digestinfo.cpp 236 | 237 | ####### Install 238 | 239 | install: FORCE 240 | 241 | uninstall: FORCE 242 | 243 | FORCE: 244 | 245 | -------------------------------------------------------------------------------- /digest-auth-session-lib/digest-auth-session.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-05-23T13:52:17 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core 8 | QT += network 9 | QT -= gui 10 | 11 | TARGET = digestauthsession 12 | CONFIG+= staticlib 13 | 14 | TEMPLATE = lib 15 | 16 | OBJECTS_DIR=bin 17 | DESTDIR = release 18 | QMAKE_CXXFLAGS += -std=c++0x 19 | 20 | SOURCES += \ 21 | utils/stringutil.cpp \ 22 | DigestManager.cpp \ 23 | Digestinfo.cpp 24 | 25 | HEADERS += \ 26 | utils/stringutil.h \ 27 | IDigestListener.h \ 28 | digeststruct.h \ 29 | DigestManager.h \ 30 | Digestinfo.h 31 | 32 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/libs/ -lhttpdecoder 33 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/libs/ -lhttpdecoder 34 | else:unix: LIBS += -L$$PWD/libs/ -lhttpdecoder 35 | 36 | INCLUDEPATH += $$PWD/libs 37 | DEPENDPATH += $$PWD/libs 38 | 39 | QMAKE_CLEAN += -r $${PWD}/$${DESTDIR} 40 | 41 | QMAKE_POST_LINK +=$$quote(rsync -avm --include=*/ --include=*.h --exclude=* $${PWD}/$${SOURCES_DIR}/ $${PWD}/$${DESTDIR}) 42 | -------------------------------------------------------------------------------- /digest-auth-session-lib/digeststruct.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | digeststruct.h 26 | 27 | Algorithm and session type structure for digest authentication / session and cookie session 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef DIGESTSTRUCT_H 33 | #define DIGESTSTRUCT_H 34 | 35 | enum digest_algorithm{ 36 | ALGO_MD5, 37 | ALGO_SHA1 38 | }; 39 | 40 | enum session_type{ 41 | SESSION_COOKIE, 42 | SESSION_DIGEST 43 | }; 44 | 45 | #endif // DIGESTSTRUCT_H 46 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/httpserverimpl/clientSocket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | clientsocket.h 26 | 27 | http client object featuring one physical http connection 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef CLIENTSOCKET_H 33 | #define CLIENTSOCKET_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include "httpserverinter/IHttpClient.h" 39 | 40 | class ClientSocket : public IHttpClient 41 | { 42 | 43 | public: 44 | 45 | /** 46 | * @brief ClientSocket::ClientSocket 47 | * Build one client 48 | */ 49 | ClientSocket(); 50 | 51 | 52 | ~ClientSocket(); 53 | 54 | /** 55 | * @brief getPeerAddress 56 | * Retrieve client ip address 57 | * @return 58 | */ 59 | std::string getPeerAddress(); 60 | 61 | /** 62 | * close websoclet client object 63 | * 64 | * @return 65 | * 0 if success -1 if error 66 | */ 67 | int close(); 68 | 69 | /** 70 | * Send a message to HTTP client 71 | * 72 | * @param string 73 | * Message to be sent to client 74 | * @return 75 | * 0 if success -1 if error 76 | */ 77 | void sendHttpMessage(std::string message); 78 | 79 | /** 80 | * @brief setSocketClient 81 | * Define client socket for this object 82 | * @param clientSocket 83 | * client socket 84 | */ 85 | void setSocketClient(QTcpSocket * clientSocket); 86 | 87 | void writeStringToSocket(std::string message); 88 | 89 | void writeByteArrayToSocket(const QByteArray array); 90 | 91 | void flush(); 92 | 93 | void writeCharToSocket(char * data,int size); 94 | 95 | private: 96 | 97 | /** 98 | * @brief clientSocket 99 | * client socket 100 | */ 101 | QTcpSocket* clientSocket; 102 | }; 103 | 104 | #endif // CLIENTSOCKET_H 105 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/httpserverimpl/httpserver.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HttpServer.h 26 | 27 | Http server main process class 28 | 29 | manage incoming connections 30 | manage socket encryption for SSL socket 31 | manage process of incoming data from client socket 32 | 33 | @author Bertrand Martel 34 | @version 1.0 35 | */ 36 | #ifndef HTTPSERVER_H 37 | #define HTTPSERVER_H 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include "protocol/inter/http/httpconsumer.h" 45 | #include "protocol/http/httpdecoder.h" 46 | #include "clientSocket.h" 47 | #include "QSslCertificate" 48 | #include "QList" 49 | #include "QSslKey" 50 | #include "httpserverinter/IClientEventListener.h" 51 | #include 52 | #include "protocol/inter/http/httpframe.h" 53 | /** 54 | * @brief The HttpServer class 55 | * Http server main process class 56 | * 57 | *
    58 | *
  • manage incoming connections
  • 59 | *
  • manage socket encryption for SSL socket
  • 60 | *
  • manage process of incoming data from client socket
  • 61 | *
62 | */ 63 | class HttpServer: public QTcpServer 64 | { 65 | 66 | Q_OBJECT 67 | public: 68 | 69 | /** 70 | * @brief HttpServer 71 | * Http server build object 72 | * @param parent 73 | */ 74 | HttpServer(QObject * parent = 0); 75 | 76 | /** 77 | * @brief socketClientList 78 | * socket client list 79 | */ 80 | static std::map socketClientList; 81 | 82 | ~HttpServer(); 83 | 84 | /** 85 | * @brief HttpServer::addClientEventListener 86 | * add a client event listener to list 87 | * @param clientListener 88 | * client listener 89 | */ 90 | void addClientEventListener(IClientEventListener * clientListener); 91 | 92 | /** 93 | * @brief HttpServer::setSSL 94 | * set Http server to secured Http server 95 | * @param use_ssl 96 | */ 97 | void setSSL(bool use_ssl); 98 | 99 | /** 100 | * @brief HttpServer::setPublicCert 101 | * set public server cert 102 | * @param cert 103 | * public certificate 104 | */ 105 | void setPublicCert(QSslCertificate cert); 106 | 107 | /** 108 | * @brief HttpServer::setCaCert 109 | * set certification authoritycert 110 | * @param cert 111 | * certification authority cert 112 | */ 113 | void setCaCert(QList< QSslCertificate > cert); 114 | 115 | /** 116 | * @brief HttpServer::setPrivateCert 117 | * set private certificate 118 | * @param cert 119 | * private certificate 120 | */ 121 | void setPrivateCert(QSslKey key); 122 | 123 | 124 | /** 125 | * @brief HttpServer::containsHttpProcessedFrames 126 | * check if http frame list buffer already contains finished http processed frame or no 127 | * @param frameList 128 | * list of http frames 129 | * @return 130 | */ 131 | bool containsHttpProcessedFrames(std::vector frameList); 132 | 133 | /** 134 | * @brief HttpServer::set_debug 135 | * activate / desactivate debug 136 | * @param use_ssl 137 | */ 138 | void set_debug(bool state); 139 | 140 | private slots: 141 | 142 | /** 143 | * @brief incomingData 144 | * slot called when data comes from client socket 145 | */ 146 | void incomingData(); 147 | 148 | /** 149 | * @brief handleNewConnection 150 | * called when a new connection pop up 151 | */ 152 | void handleNewConnection(); 153 | 154 | /** 155 | * @brief slot_connected 156 | * called when a socket connect successfully to server 157 | */ 158 | void slot_connected (); 159 | 160 | /** 161 | * @brief slot_disconnected 162 | * called when a socket disconnect from server 163 | */ 164 | void slot_disconnected (); 165 | 166 | void ready(); 167 | 168 | void slot_error (QAbstractSocket::SocketError err); 169 | void slot_hostFound (); 170 | void slot_proxyAuthenticationRequired (const QNetworkProxy &, QAuthenticator *); 171 | void slot_stateChanged (QAbstractSocket::SocketState state); 172 | 173 | //bunch of slots used to check different state of SSL encryption process through QTNetwork processing 174 | void slot_encrypted (); 175 | void slot_encryptedBytesWritten (qint64 written); 176 | void slot_modeChanged (QSslSocket::SslMode mode); 177 | void slot_peerVerifyError (const QSslError &); 178 | void slot_sslErrors (const QList &); 179 | 180 | private: 181 | 182 | /** 183 | * @brief nextPendingConnection 184 | * overidde of next pending connection for queuing socket in a list 185 | * @return 186 | */ 187 | QSslSocket* nextPendingConnection(); 188 | 189 | /** 190 | * @brief incomingConnection 191 | * new connection has come 192 | * @param socketDescriptor 193 | */ 194 | void incomingConnection(int socketDescriptor); 195 | 196 | /** 197 | * @brief HttpServer::startServerEncryption 198 | * add respective certificates for SSL encryption 199 | * 200 | * @param clientSocket 201 | * ssl client socket 202 | */ 203 | void startServerEncryption(QSslSocket* clientSocket); 204 | 205 | /** 206 | * @brief HttpServer::connectSocketSignals 207 | * connect signals to slots : we take the maximum of slots here to manage errors quickly 208 | * @param clientSocket 209 | * client socket incoming 210 | */ 211 | void connectSocketSignals(QSslSocket* clientSocket); 212 | 213 | /** 214 | * @brief HttpServer::closeClientSocket 215 | * close client socket function 216 | * @param socket 217 | * client socket 218 | */ 219 | void closeClientSocket(QSslSocket* socket); 220 | 221 | //ssl certs used to encrypt ssl socket 222 | 223 | /** 224 | * @brief localCertificate 225 | * public certificate 226 | */ 227 | QSslCertificate localCertificate; 228 | 229 | /** 230 | * @brief caCertificate 231 | * certification authority list of certificates 232 | */ 233 | QList< QSslCertificate > caCertificate; 234 | 235 | /** 236 | * @brief keyCertificate 237 | * private certificate 238 | */ 239 | QSslKey keyCertificate; 240 | 241 | /** 242 | * @brief consumer 243 | * http consumer used to retrieve chunk of http frames 244 | */ 245 | httpconsumer * consumer; 246 | 247 | /** 248 | * @brief decoder 249 | * http decoder used to decode http frames streaming 250 | */ 251 | httpdecoder decoder; 252 | 253 | /** 254 | * @brief debug 255 | * debug state for Http server 256 | */ 257 | bool debug; 258 | 259 | /** 260 | * @brief ssl 261 | * define if Http protocol must use encryption or not 262 | */ 263 | bool ssl; 264 | 265 | /** 266 | * @brief clientEventListenerList 267 | * list of client event listener 268 | */ 269 | std::vector clientEventListenerList; 270 | 271 | /** 272 | * @brief queue 273 | * used to store connection in a list 274 | */ 275 | QQueue queue; 276 | }; 277 | 278 | 279 | #endif // HTTPSERVER_H 280 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/httpserverinter/IClientEventListener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IClientEventListener.h 26 | 27 | Define all client socket event that can happen and that will pop event in class that will inherit this one 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef ICLIENTEVENTLISTENER_H 33 | #define ICLIENTEVENTLISTENER_H 34 | 35 | #include "IHttpClient.h" 36 | #include "string" 37 | #include "protocol/inter/http/IhttpFrame.h" 38 | 39 | /** 40 | * @brief The IClientEventListener class 41 | * Client Socket event listener template class 42 | */ 43 | class IClientEventListener 44 | { 45 | 46 | public : 47 | 48 | /** 49 | * called when an http request has been received from client 50 | * 51 | * @param client 52 | * client object 53 | * @param message 54 | * message delivered 55 | */ 56 | virtual void onHttpRequestReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address)= 0; 57 | 58 | /** 59 | * called when an http response has been received from client 60 | * 61 | * @param client 62 | * client object 63 | * @param message 64 | * message delivered 65 | */ 66 | virtual void onHttpResponseReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address)= 0; 67 | 68 | }; 69 | 70 | 71 | #endif // ICLIENTEVENTLISTENER_H 72 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/httpserverinter/IHttpClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IWebsocketClient.h 26 | 27 | Define generic template for http client socket 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef IHTTPCLIENT_H 33 | #define IHTTPCLIENT_H 34 | #include "string" 35 | #include "QByteArray" 36 | 37 | class IHttpClient 38 | { 39 | 40 | public : 41 | /** 42 | * Send http message to client 43 | * 44 | * @param string 45 | * Message to be sent to client 46 | * @return 47 | * 0 if success -1 if error 48 | */ 49 | virtual void sendHttpMessage(std::string message)= 0; 50 | 51 | virtual void writeStringToSocket(std::string message)=0; 52 | 53 | virtual void writeByteArrayToSocket(const QByteArray array)=0; 54 | 55 | virtual void flush()=0; 56 | 57 | virtual void writeCharToSocket(char * data,int size)=0; 58 | 59 | }; 60 | 61 | #endif // IHTTPCLIENT_H 62 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/libhttpServer.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bertrandmartel/digest-auth-session-cpp/HEAD/digest-auth-session-lib/libs/libhttpServer.a -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/libhttpdecoder.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bertrandmartel/digest-auth-session-cpp/HEAD/digest-auth-session-lib/libs/libhttpdecoder.a -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/http/httpconstants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpconstants.h 26 | HTTP constants file 27 | Regroup all constants used for HTTP parser 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPCONSTANTS_H 33 | #define HTTPCONSTANTS_H 34 | #include "vector" 35 | #include "string" 36 | 37 | /** 38 | * @brief The httpconstants class 39 | * store HTTP parser constants 40 | */ 41 | class httpconstants 42 | { 43 | 44 | public: 45 | 46 | #define HTTP_HEADERS_CONTENT_LENGTH "Content-Length" 47 | 48 | #define HTTP_METHOD_GET "GET" 49 | 50 | #define HTTP_METHOD_POST "POST" 51 | 52 | #define HTTP_METHOD_PUT "PUT" 53 | 54 | #define HTTP_METHOD_DELETE "DELETE" 55 | 56 | // struct for status code / status code phrase 57 | typedef struct statusCodeStruct 58 | { 59 | int code_value; 60 | std::string code_phrase; 61 | 62 | statusCodeStruct(int code_value,std::string code_phrase) : 63 | code_value(code_value), code_phrase(code_phrase){} 64 | } statusCode; 65 | 66 | /** 67 | * @brief http_status_code_list 68 | * list of status code / code phrase 69 | */ 70 | static std::vector http_status_code_list; 71 | 72 | /** 73 | * @brief static_init 74 | * list of status code is statically stored : this must be called only once to avoid doublons (TODO : check if there is another way) 75 | */ 76 | static void static_init(){ 77 | http_status_code_list.push_back(statusCodeStruct(100, "Continue" )); 78 | http_status_code_list.push_back(statusCodeStruct(101, "Switching Protocols" )); 79 | http_status_code_list.push_back(statusCodeStruct(200, "OK" )); 80 | http_status_code_list.push_back(statusCodeStruct(201, "Created" )); 81 | http_status_code_list.push_back(statusCodeStruct(202, "Accepted" )); 82 | http_status_code_list.push_back(statusCodeStruct(203, "Non-Authoritative Information" )); 83 | http_status_code_list.push_back(statusCodeStruct(204, "No Content" )); 84 | http_status_code_list.push_back(statusCodeStruct(205, "Reset Content" )); 85 | http_status_code_list.push_back(statusCodeStruct(206, "Partial Content" )); 86 | http_status_code_list.push_back(statusCodeStruct(300, "Multiple Choices" )); 87 | http_status_code_list.push_back(statusCodeStruct(301, "Moved Permanently" )); 88 | http_status_code_list.push_back(statusCodeStruct(302, "Found" )); 89 | http_status_code_list.push_back(statusCodeStruct(303, "See Other" )); 90 | http_status_code_list.push_back(statusCodeStruct(304, "Not Modified" )); 91 | http_status_code_list.push_back(statusCodeStruct(305, "Use Proxy" )); 92 | http_status_code_list.push_back(statusCodeStruct(307, "Temporary Redirect" )); 93 | http_status_code_list.push_back(statusCodeStruct(400, "Bad Request" )); 94 | http_status_code_list.push_back(statusCodeStruct(401, "Unauthorized" )); 95 | http_status_code_list.push_back(statusCodeStruct(402, "Payment Required" )); 96 | http_status_code_list.push_back(statusCodeStruct(403, "Forbidden" )); 97 | http_status_code_list.push_back(statusCodeStruct(404, "Not Found" )); 98 | http_status_code_list.push_back(statusCodeStruct(405, "Method Not Allowed" )); 99 | http_status_code_list.push_back(statusCodeStruct(406, "Not Acceptable" )); 100 | http_status_code_list.push_back(statusCodeStruct(407, "Proxy Authentication Required" )); 101 | http_status_code_list.push_back(statusCodeStruct(408, "Request Time-out" )); 102 | http_status_code_list.push_back(statusCodeStruct(409, "Conflict" )); 103 | http_status_code_list.push_back(statusCodeStruct(410, "Gone" )); 104 | http_status_code_list.push_back(statusCodeStruct(411, "Length Required" )); 105 | http_status_code_list.push_back(statusCodeStruct(412, "Precondition Failed" )); 106 | http_status_code_list.push_back(statusCodeStruct(413, "Request Entity Too Large" )); 107 | http_status_code_list.push_back(statusCodeStruct(414, "Request-URI Too Large" )); 108 | http_status_code_list.push_back(statusCodeStruct(415, "Unsupported Media Type" )); 109 | http_status_code_list.push_back(statusCodeStruct(416, "Requested range not satisfiable" )); 110 | http_status_code_list.push_back(statusCodeStruct(417, "Expectation Failed" )); 111 | http_status_code_list.push_back(statusCodeStruct(500, "Internal Server Error" )); 112 | http_status_code_list.push_back(statusCodeStruct(501, "Not Implemented" )); 113 | http_status_code_list.push_back(statusCodeStruct(502, "Bad Gateway" )); 114 | http_status_code_list.push_back(statusCodeStruct(503, "Service Unavailable" )); 115 | http_status_code_list.push_back(statusCodeStruct(504, "Gateway Time-out" )); 116 | http_status_code_list.push_back(statusCodeStruct(505, "HTTP Version not supported" )); 117 | } 118 | }; 119 | 120 | #endif // HTTPCONSTANTS_H 121 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/http/httpdecoder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HttpDecoder.h 26 | HTTP Decoder main class 27 | Will decode according to CRLF presence or add data to http consumer buffer 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPDECODER_H 33 | #define HTTPDECODER_H 34 | 35 | #include "protocol/inter/http/httpconsumer.h" 36 | #include "QByteArray" 37 | 38 | /** 39 | * @brief The HttpDecoder class 40 | * 41 | * Http decoder main input class 42 | */ 43 | class httpdecoder 44 | { 45 | 46 | public : 47 | 48 | httpdecoder(); 49 | 50 | /** 51 | * @brief httpDecode 52 | * http decoder 53 | * 54 | * @param consumer 55 | * http client consumer featuring connection monitoring 56 | * @param data 57 | * non-blocking or blocking data stream 58 | */ 59 | void httpdecode(httpconsumer * consumer,QByteArray* data); 60 | 61 | }; 62 | 63 | #endif // HTTPDECODER_H 64 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/http/httpdecoder_global.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpdecoder_global.h 26 | This will make access this library to QLibrary (no need to access header and lib) 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef HTTPDECODER_GLOBAL_H 32 | #define HTTPDECODER_GLOBAL_H 33 | 34 | #include 35 | 36 | #if defined(HTTPDECODER_LIBRARY) 37 | # define HTTPDECODERSHARED_EXPORT Q_DECL_EXPORT 38 | #else 39 | # define HTTPDECODERSHARED_EXPORT Q_DECL_IMPORT 40 | #endif 41 | 42 | #endif // HTTPDECODER_GLOBAL_H 43 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/http/httpparser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpparser.h 26 | HTTP Parser 27 | Will parse streaming data through parseHttp() method 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPPARSER_H 33 | #define HTTPPARSER_H 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "protocol/inter/http/httpconsumer.h" 39 | 40 | /** 41 | * @brief The HttpParser class 42 | * Main HTTP Parser
43 | * Will parse streaming data 44 | */ 45 | class httpparser 46 | { 47 | 48 | public: 49 | httpparser(); 50 | 51 | /** 52 | * @brief parseHttp 53 | * parse streaming data 54 | * 55 | * @param data 56 | * streaming data 57 | */ 58 | void parseHttp(QByteArray* data,httpconsumer * consumer); 59 | 60 | /** 61 | * @brief setDebug 62 | * set debug mode for http parser 63 | * @param debug 64 | */ 65 | void setDebug(bool debug); 66 | 67 | /** 68 | * @brief getHeaders 69 | * retrieve http headers 70 | * @return 71 | */ 72 | std::map< std::string,std::string > *getHeaders(); 73 | 74 | private: 75 | 76 | /** 77 | * @brief isMethod 78 | * check if input data is a valid HTTP rest method 79 | * 80 | * @param data 81 | * data to be tested 82 | * @return 83 | * true if data is valid REST HTTP method 84 | */ 85 | bool isMethod(std::string data); 86 | 87 | /** 88 | * @brief isStatusNum 89 | * check if input data is a valid HTTP status code 90 | * @param data 91 | * data to be tested 92 | * @return 93 | * true if data is valid HTTP status code 94 | */ 95 | bool isStatusNum(std::string data); 96 | 97 | /** 98 | * @brief debug 99 | * debug activation 100 | */ 101 | bool debug; 102 | }; 103 | 104 | #endif // HTTPPARSER_H 105 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/http/httpstates.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpstates.h 26 | HTTP parser states 27 | Regroup all states present in http parser 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPSTATES_H 33 | #define HTTPSTATES_H 34 | 35 | #define HTTP_STATE_INIT 0 36 | 37 | #define HTTP_STATE_VERSION 1 38 | 39 | #define HTTP_STATE_HEADERS 2 40 | 41 | #define HTTP_STATE_BODY 3 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/inter/http/IhttpFrame.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IHttpFrame.h 26 | HTTP frame template 27 | Regroup all http metadata for one http frame 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef IHTTPFRAME_H 33 | #define IHTTPFRAME_H 34 | 35 | #include "string" 36 | #include "map" 37 | 38 | /** 39 | * @brief The IHttpFrame class 40 | * Interface defining all http metadata decoded from http decoder 41 | * 42 | */ 43 | class Ihttpframe{ 44 | 45 | public: 46 | /** 47 | * @brief getUri 48 | * retrieve HTTP uri 49 | * @return 50 | */ 51 | virtual std::string getUri()= 0; 52 | 53 | /** 54 | * @brief setUri 55 | * set http uri value 56 | * @param uri 57 | */ 58 | virtual void setUri(std::string uri)= 0; 59 | 60 | /** 61 | * @brief getMethod 62 | * retrieve HTTP method 63 | * @return 64 | */ 65 | virtual std::string getMethod()= 0; 66 | 67 | /** 68 | * @brief setMethod 69 | * set http method 70 | * @param method 71 | */ 72 | virtual void setMethod(std::string method)= 0; 73 | 74 | /** 75 | * @brief getBodyLength 76 | * retrieve length of body 77 | * @return 78 | */ 79 | virtual std::string getBody()= 0; 80 | 81 | /** 82 | * @brief setBody 83 | * set http body value 84 | * @param body 85 | */ 86 | virtual void setBody(std::string body)= 0; 87 | 88 | /** 89 | * @brief getQueryString 90 | * retrieve query string value 91 | * @return 92 | */ 93 | virtual std::string getQueryString()= 0; 94 | 95 | /** 96 | * @brief setQueryString 97 | * set http query string value 98 | * @param querystring 99 | */ 100 | virtual void setQueryString(std::string querystring)= 0; 101 | 102 | /** 103 | * @brief getStatusCode 104 | * retrieve status code 105 | * @return 106 | */ 107 | virtual int getStatusCode()= 0; 108 | 109 | /** 110 | * @brief setStatusCode 111 | * set status code value 112 | * @param statusCode 113 | */ 114 | virtual void setStatusCode(int statusCode)= 0; 115 | 116 | /** 117 | * @brief getHeaders 118 | * retrieve http headers 119 | * @return 120 | */ 121 | virtual std::map< std::string,std::string > getHeaders()= 0; 122 | 123 | /** 124 | * @brief httpConsumer::getProcessState 125 | * retrieve true if all data has been processed in current buffer 126 | * @return 127 | * 128 | */ 129 | virtual bool isFinishedProcessing()= 0; 130 | 131 | /** 132 | * @brief setFinishedProcessing 133 | * set processing frame state 134 | * @param processing 135 | */ 136 | virtual void setFinishedProcessing(bool processing)= 0; 137 | 138 | }; 139 | 140 | #endif // IHTTPFRAME_H 141 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/inter/http/httpconsumer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpconsumer.cpp 26 | HTTP Consumer client 27 | This object permits to store http life cycle into your own design and monitor your parsing in a blocking or non-blocking socket configuration 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPCONSUMER_H 33 | #define HTTPCONSUMER_H 34 | 35 | #include "string" 36 | #include "QByteArray" 37 | #include "map" 38 | #include "IhttpFrame.h" 39 | #include "vector" 40 | #include "httpframe.h" 41 | 42 | /** 43 | * @brief httpConsumer::httpConsumer 44 | * Consumer client of http decoder
45 | * This object permits to store http life cycle into your own design and monitor your parsing in a blocking or non-blocking socket configuration 46 | */ 47 | class httpconsumer 48 | { 49 | public: 50 | 51 | ~httpconsumer(); 52 | 53 | /** 54 | * @brief httpConsumer::httpConsumer 55 | * Consumer client of http decoder
56 | * This object permits to store http life cycle into your own design and monitor your parsing in a blocking or non-blocking socket configuration 57 | */ 58 | httpconsumer(); 59 | 60 | /** 61 | * @brief httpConsumer::clearBuffer 62 | * clear current buffer 63 | */ 64 | void clearBuffer(); 65 | 66 | /** 67 | * @brief httpConsumer::appendToBuffer 68 | * append some data to buffer 69 | *@param data 70 | * data to be appended 71 | * @return 72 | * pointer to data 73 | */ 74 | int appendToBuffer(QByteArray* data); 75 | 76 | /** 77 | * @brief httpConsumer::getBuffer 78 | * retrieve current buffer 79 | *@return 80 | */ 81 | QByteArray getBuffer(); 82 | 83 | /** 84 | * @brief httpConsumer::getProcessState 85 | * retrieve true if all data has been processed in current buffer 86 | * @return 87 | * 88 | */ 89 | bool isFinishedProcessing(); 90 | 91 | /** 92 | * @brief setFinishedProcessing 93 | * set processing frame state 94 | * @param processing 95 | */ 96 | void setFinishedProcessing(bool processing); 97 | 98 | /** 99 | * @brief setDebug 100 | * set debug mode for consumer 101 | * @param debug 102 | */ 103 | void setDebug(bool debug); 104 | 105 | /** 106 | * @brief bodyIndex 107 | * index of body in buffer element 108 | */ 109 | int getBodyIndex(); 110 | 111 | /** 112 | * @brief setBodyIndex 113 | * set body index 114 | * @param bodyIndexArg 115 | */ 116 | void setBodyIndex(int bodyIndexArg); 117 | 118 | /** 119 | * @brief bodyProcess 120 | * get to know if HTTP body is to be parsed or not 121 | */ 122 | bool getBodyProcess(); 123 | 124 | /** 125 | * @brief setBodyProcess 126 | * set HTTP body parsing state 127 | * @param processArg 128 | */ 129 | void setBodyProcess(bool processArg); 130 | 131 | /** 132 | * @brief bodyLength 133 | * length of body 134 | */ 135 | int getBodyLength(); 136 | 137 | /** 138 | * @brief setBodyLength 139 | * set body length 140 | * @param length 141 | */ 142 | void setBodyLength(int length); 143 | 144 | /** 145 | * @brief httpState 146 | * http parser current state 147 | */ 148 | int getHttpState(); 149 | 150 | /** 151 | * @brief setHttpState 152 | * set http parser state 153 | * @param http_state 154 | */ 155 | void setHttpState(int http_state); 156 | 157 | /** 158 | * @brief isDebug 159 | * debug state 160 | * @return 161 | */ 162 | bool isDebug(); 163 | 164 | /** 165 | * @brief getHttpFrameList 166 | * retrieve http frame object list 167 | * @return 168 | */ 169 | std::vector getHttpFrameList(); 170 | 171 | /** 172 | * @brief httpConsumer::addNewHttpFrame 173 | * add a new http frame in the list 174 | * @param frame 175 | */ 176 | void addNewHttpFrame(httpframe frame); 177 | 178 | /** 179 | * @brief getCurrentHttpFrame 180 | * retrieve current http frame object 181 | * @return 182 | */ 183 | httpframe *getCurrentHttpFrame(); 184 | 185 | /** 186 | * @brief setHttpFrameList 187 | * set http frame list object 188 | * @param list 189 | * pointer to vector of IHttp frames 190 | */ 191 | void setHttpFrameList(std::vector list); 192 | 193 | private: 194 | 195 | /** 196 | * @brief buffer 197 | * buffer used to store current unfinished http stream data (unfinished => not terminating with carriage return) 198 | */ 199 | QByteArray buffer; 200 | 201 | /** 202 | * @brief bodyIndex 203 | * index of body in buffer element 204 | */ 205 | int bodyIndex; 206 | 207 | /** 208 | * @brief bodyProcess 209 | * get to know if HTTP body is to be parsed or not 210 | */ 211 | bool bodyProcess; 212 | 213 | /** 214 | * @brief bodyLength 215 | * length of body 216 | */ 217 | int bodyLength; 218 | 219 | /** 220 | * @brief httpState 221 | * http parser current state 222 | */ 223 | int httpState; 224 | 225 | /** 226 | * @brief processFrame 227 | * indicate that HTTP frame has finished processing 228 | */ 229 | bool finishedProcessing; 230 | 231 | /** 232 | * @brief debug 233 | * debug activation 234 | */ 235 | bool debug; 236 | 237 | /** 238 | * @brief httpFrameList 239 | * list of http frames 240 | */ 241 | std::vector httpFrameList; 242 | 243 | }; 244 | 245 | #endif // HTTPCONSUMER_H 246 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/protocol/inter/http/httpframe.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef HTTPFRAME_H 25 | #define HTTPFRAME_H 26 | 27 | #include "IhttpFrame.h" 28 | 29 | class httpframe : public Ihttpframe 30 | { 31 | public: 32 | httpframe(); 33 | 34 | ~httpframe(); 35 | 36 | /** 37 | * @brief getUri 38 | * retrieve HTTP uri 39 | * @return 40 | */ 41 | std::string getUri(); 42 | 43 | /** 44 | * @brief setUri 45 | * set http uri value 46 | * @param uri 47 | */ 48 | void setUri(std::string uri); 49 | 50 | /** 51 | * @brief getMethod 52 | * retrieve HTTP method 53 | * @return 54 | */ 55 | std::string getMethod(); 56 | 57 | /** 58 | * @brief setMethod 59 | * set http method 60 | * @param method 61 | */ 62 | void setMethod(std::string method); 63 | 64 | /** 65 | * @brief getBodyLength 66 | * retrieve length of body 67 | * @return 68 | */ 69 | std::string getBody(); 70 | 71 | /** 72 | * @brief setBody 73 | * set http body value 74 | * @param body 75 | */ 76 | void setBody(std::string body); 77 | 78 | /** 79 | * @brief getQueryString 80 | * retrieve query string value 81 | * @return 82 | */ 83 | std::string getQueryString(); 84 | 85 | /** 86 | * @brief setQueryString 87 | * set http query string value 88 | * @param querystring 89 | */ 90 | void setQueryString(std::string querystring); 91 | 92 | /** 93 | * @brief getStatusCode 94 | * retrieve status code 95 | * @return 96 | */ 97 | int getStatusCode(); 98 | 99 | /** 100 | * @brief setStatusCode 101 | * set status code value 102 | * @param statusCode 103 | */ 104 | void setStatusCode(int statusCode); 105 | 106 | /** 107 | * @brief getHeaders 108 | * retrieve http headers 109 | * @return 110 | */ 111 | std::map< std::string,std::string > getHeaders(); 112 | 113 | /** 114 | * @brief httpConsumer::getProcessState 115 | * retrieve true if all data has been processed in current buffer 116 | * @return 117 | * 118 | */ 119 | bool isFinishedProcessing(); 120 | 121 | /** 122 | * @brief setFinishedProcessing 123 | * set processing frame state 124 | * @param processing 125 | */ 126 | void setFinishedProcessing(bool processing); 127 | 128 | /** 129 | * @brief setHeaders 130 | * set http headers 131 | * @param header 132 | */ 133 | void setHeaders(std::map header); 134 | 135 | private : 136 | 137 | /** 138 | * @brief querystring 139 | * HTTP querystring 140 | */ 141 | std::string querystring; 142 | 143 | /** 144 | * @brief uri 145 | * uri of HTTP frame 146 | */ 147 | std::string uri; 148 | 149 | /** 150 | * @brief method 151 | * method of HTTP frame 152 | */ 153 | std::string method; 154 | 155 | /** 156 | * @brief body 157 | * body of HTTP frame 158 | */ 159 | std::string body; 160 | 161 | 162 | /** 163 | * @brief statusNum 164 | * status code of HTTP frame 165 | */ 166 | int statusCode; 167 | 168 | 169 | /** 170 | * @brief headers 171 | * HTTP headers 172 | */ 173 | std::map headers; 174 | 175 | /** 176 | * @brief processFrame 177 | * indicate that HTTP frame has finished processing 178 | */ 179 | bool finishedProcessing; 180 | }; 181 | 182 | #endif // HTTPFRAME_H 183 | -------------------------------------------------------------------------------- /digest-auth-session-lib/libs/utils/stringutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | stringutils.h 3 | Utility funcions for http parser 4 | 5 | @author Bertrand Martel 6 | @version 1.0 7 | */ 8 | #ifndef STRINGUTILS_H 9 | #define STRINGUTILS_H 10 | 11 | #include "stringutils.h" 12 | #include "vector" 13 | #include "string" 14 | 15 | /** 16 | * @brief The stringutils class 17 | * String utility functions 18 | */ 19 | class stringutils 20 | { 21 | public: 22 | 23 | /** 24 | * @brief split 25 | * split a string with a character delimiter 26 | * @param s 27 | * string to split 28 | * @param delim 29 | * character delimiter 30 | * @return 31 | * vector of splitted string 32 | */ 33 | static std::vector split(std::string s, char delim); 34 | 35 | /** 36 | * @brief isNum 37 | * check if char * is numeric data 38 | * @param s 39 | * char * input 40 | * @return 41 | * true if data is numeric 42 | */ 43 | static bool isNum(char *s); 44 | 45 | }; 46 | 47 | #endif // STRINGUTILS_H 48 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/DigestManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | DigestManager.h 26 | Client socket managing event handler 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef DIGESTMANAGER_H 32 | #define DIGESTMANAGER_H 33 | 34 | #include "Digestinfo.h" 35 | #include "QList" 36 | #include "digeststruct.h" 37 | #include "IDigestListener.h" 38 | #include "QDateTime" 39 | #include "map" 40 | 41 | /* nonce structure used to store stateful data about nonce creation / lifetime */ 42 | typedef struct { 43 | std::string nonce; // nonce value 44 | unsigned long expiring_date; // expiring date in millisecond since 1970 45 | unsigned int nonce_count; // nonce server count 46 | bool stale; // true if former nonce was rejected due to expiration (NOT IMPLEMENTED FOR NOW) 47 | std::string session_id; // session id (only for COOKIE session type => this must match an entry in session structure below for this type of session) 48 | } nonce; 49 | 50 | /* session structure used to store stateful data about session entry for COOKIE session type*/ 51 | typedef struct{ 52 | QDateTime session_start_date; // session record date 53 | bool validity; // validity of session entry 54 | } session; 55 | 56 | /** 57 | * @brief The DigestManager class 58 | * Client socket managing event handler 59 | */ 60 | class DigestManager{ 61 | 62 | public: 63 | 64 | /** 65 | * @brief DigestManager 66 | * build client socket handler 67 | */ 68 | DigestManager(); 69 | 70 | ~DigestManager(); 71 | 72 | /** 73 | * @brief process_digest 74 | * process digest request / response according to method / uri / headers given in parameters.
75 | * Will return following http content body according digest processing : 76 | *
    77 | *
  • unauthorized_page : when client has not been authorized yet / or token expired / or authorization issue happened
  • 78 | *
  • internal_error_page : when processing error occured
  • 79 | *
  • expected_page : when client is fully authorized and session token is valid
  • 80 | *
81 | * @param method 82 | * http method 83 | * @param uri 84 | * http uri 85 | * @param headers 86 | * http headers 87 | * @param realm 88 | * chosen realm for given uri 89 | * @return 90 | * DigestInfo 91 | */ 92 | DigestInfo process_digest(std::string method,std::string uri,std::map headers,std::string realm); 93 | 94 | /** 95 | * @brief DigestManager::remove_expired_nonces 96 | * Remove all nonces in map that expired 97 | */ 98 | void remove_expired_nonces(); 99 | 100 | /** 101 | * @brief DigestManager::remove_expired_sessions 102 | * Remove all session in map that expired 103 | */ 104 | void remove_expired_sessions(); 105 | 106 | /** 107 | * @brief getAuthenticationCookieField 108 | * Retrieve HSID value from cookie http header 109 | * 110 | * @param cookieStr 111 | * cookie header value 112 | * @return 113 | */ 114 | std::string getAuthenticationCookieField(std::string cookieStr); 115 | 116 | /** 117 | * @brief splitHeader 118 | * @param header 119 | * @param delim 120 | * @return 121 | */ 122 | std::map splitHeader(std::string header,char delim); 123 | 124 | /** 125 | * @brief remove_session_for_headers 126 | * Remove a session (cookie or digest) 127 | * @param headers 128 | * @return 129 | */ 130 | int remove_session_for_headers(std::map *headers); 131 | 132 | /** 133 | * @brief DigestManager::generateHandshakeProcess 134 | * build digest authentication request 135 | * @param host 136 | * host address 137 | * @param path_realm 138 | * realm used for authentication 139 | * @return 140 | * DigestInfo 141 | */ 142 | DigestInfo generateHandshakeProcess(std::string host,std::string realm); 143 | 144 | /** 145 | * @brief DigestManager::generateRandomNum 146 | * Generate random alpha numeric string 147 | * @param num 148 | * length of random string 149 | * @return 150 | */ 151 | std::string generateRandomNum(unsigned int num); 152 | 153 | /** 154 | * @brief DigestManager::processDigestResponse 155 | * Process digest response request to authenticate and validate session cookie 156 | * 157 | * @param authorizationHeader 158 | * header Authorization 159 | * @param cookieHeader 160 | * Cookie header 161 | * @param realm 162 | * realm used for this authentication 163 | * @param http_method_requested 164 | * http method requested by client 165 | * @param uri_requested 166 | * uri requested by client 167 | * @return 168 | * DigestInfo 169 | */ 170 | DigestInfo processDigestResponse(std::string authorizationHeader,std::string cookieHeader,std::string realm,std::string http_method_requested,std::string uri_requested); 171 | 172 | /** 173 | * @brief DigestManager::set_show_algorithm 174 | * algorithm used in digest authentication will be sent to client if set to true (default) 175 | * @param show_in_response 176 | */ 177 | void set_show_algorithm(bool show_in_response); 178 | 179 | /** 180 | * @brief DigestManager::set_digest_algorithm 181 | * Set digest algorithm used for processing hash 182 | * @param algorithm 183 | */ 184 | void set_digest_algorithm(digest_algorithm algorithm); 185 | 186 | /** 187 | * @brief DigestManager::getAlgorithm 188 | * Retrieve digest get_algorithm used for processing hash 189 | * @return 190 | */ 191 | digest_algorithm get_algorithm(); 192 | 193 | /** 194 | * @brief DigestManager::set_nonce_timeout_millis 195 | * set nonce timeout in milliseconds 196 | * @param nonce_timeout 197 | */ 198 | void set_nonce_timeout_millis(long nonce_timeout); 199 | 200 | /** 201 | * @brief DigestManager::get_nonce_timeout_millis 202 | * Retrieve nonce timeout in milliseconds 203 | * @return 204 | */ 205 | long get_nonce_timeout_millis(); 206 | 207 | /** 208 | * @brief DigestManager::set_digest_listener 209 | * Set digest listener 210 | * @param digest_listener 211 | */ 212 | void set_digest_listener(IDigestListener* digest_listener); 213 | 214 | /** 215 | * @brief DigestManager::set_session_type 216 | * Set session type (default is DIGEST session) 217 | * @param session 218 | */ 219 | void set_session_type(session_type session); 220 | 221 | /** 222 | * @brief DigestManager::get_session_type 223 | * Retrieve session type 224 | * @return 225 | */ 226 | session_type get_session_type(); 227 | 228 | /** 229 | * @brief DigestManager::set_max_session_time 230 | * Set maximum session time for user 231 | * @param session_time 232 | */ 233 | void set_max_session_time(int session_time); 234 | 235 | /** 236 | * @brief DigestManager::get_max_session_time 237 | * Retrieve maximum session time for user 238 | * @return 239 | */ 240 | int get_max_session_time(); 241 | 242 | /** 243 | * @brief show_algorithm 244 | * if set to true will show algorithm used in response to client 245 | */ 246 | bool show_algorithm; 247 | 248 | /** 249 | * @brief algorithm 250 | * algorithm used to compute hashes 251 | */ 252 | digest_algorithm algorithm; 253 | 254 | /** 255 | * @brief nonce_timeout_millis 256 | * nonce timeout in milliseconds (it is the session duration when digest session is used) 257 | */ 258 | long nonce_timeout_millis; 259 | 260 | /** 261 | * @brief digest_listener 262 | * listener for retrievinf username / password hash from storage 263 | */ 264 | IDigestListener * digest_listener; 265 | 266 | /** 267 | * @brief session_t 268 | * type of session used (can be DIGEST or COOKIE) 269 | */ 270 | session_type session_t; 271 | 272 | /** 273 | * @brief session_time_seconds 274 | * session duration for COOKIE session type (DIGEST session duration is set by nonce timeout) 275 | */ 276 | int session_time_seconds; 277 | 278 | /** 279 | * @brief nonce_map 280 | * map of nonces 281 | */ 282 | std::map< std::string, nonce> nonce_map; 283 | 284 | /** 285 | * @brief session_map 286 | * map of sessions (used only for COOKIE session) 287 | */ 288 | std::map< std::string, session> session_map; 289 | }; 290 | 291 | #endif // DIGESTMANAGER_H 292 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/Digestinfo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | DigestInfo.h 26 | Output digest information to be sent to client 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef DIGESTINFO_H 32 | #define DIGESTINFO_H 33 | 34 | #include "map" 35 | #include "string" 36 | 37 | /** 38 | * @brief The DigestInfo class 39 | * Digest information used to build http request/response 40 | */ 41 | class DigestInfo 42 | { 43 | public: 44 | 45 | /** 46 | * @brief DigestInfo 47 | * @param status_code 48 | * http status code 49 | * @param headers 50 | * http headers 51 | */ 52 | DigestInfo(int status_code,std::map< std::string,std::string> headers); 53 | 54 | ~DigestInfo(); 55 | 56 | /** 57 | * @brief get_status_code 58 | * Retrieve status code to return 59 | * @return 60 | */ 61 | int get_status_code(); 62 | 63 | /** 64 | * @brief get_headers 65 | * Retrieve headers to return 66 | * @return 67 | */ 68 | std::map< std::string,std::string >* get_headers(); 69 | 70 | private: 71 | 72 | /** 73 | * @brief status_code 74 | * http status code 75 | */ 76 | int status_code; 77 | 78 | /** 79 | * @brief headers 80 | * http headers 81 | */ 82 | std::map< std::string,std::string > headers; 83 | }; 84 | 85 | #endif // DIGESTINFO_H 86 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/IDigestListener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IDigestListener.h 26 | 27 | Generic interface for digest listener. Used to implement a listener to retrieve username / password hashe from storage 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef IDIGESTLISTENER_H 33 | #define IDIGESTLISTENER_H 34 | 35 | #include "string" 36 | #include "digeststruct.h" 37 | 38 | class IDigestListener{ 39 | 40 | public: 41 | 42 | /** 43 | * @brief getUri 44 | * retrieve HTTP uri 45 | * @return 46 | */ 47 | virtual std::string get_hash_for_username(std::string username,std::string realm,digest_algorithm algo)=0; 48 | }; 49 | 50 | #endif // IDIGESTLISTENER_H 51 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/digeststruct.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | digeststruct.h 26 | 27 | Algorithm and session type structure for digest authentication / session and cookie session 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef DIGESTSTRUCT_H 33 | #define DIGESTSTRUCT_H 34 | 35 | enum digest_algorithm{ 36 | ALGO_MD5, 37 | ALGO_SHA1 38 | }; 39 | 40 | enum session_type{ 41 | SESSION_COOKIE, 42 | SESSION_DIGEST 43 | }; 44 | 45 | #endif // DIGESTSTRUCT_H 46 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libdigestauthsession.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bertrandmartel/digest-auth-session-cpp/HEAD/digest-auth-session-lib/release/libdigestauthsession.a -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/httpserverimpl/clientSocket.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | clientsocket.h 26 | 27 | http client object featuring one physical http connection 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef CLIENTSOCKET_H 33 | #define CLIENTSOCKET_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include "httpserverinter/IHttpClient.h" 39 | 40 | class ClientSocket : public IHttpClient 41 | { 42 | 43 | public: 44 | 45 | /** 46 | * @brief ClientSocket::ClientSocket 47 | * Build one client 48 | */ 49 | ClientSocket(); 50 | 51 | 52 | ~ClientSocket(); 53 | 54 | /** 55 | * @brief getPeerAddress 56 | * Retrieve client ip address 57 | * @return 58 | */ 59 | std::string getPeerAddress(); 60 | 61 | /** 62 | * close websoclet client object 63 | * 64 | * @return 65 | * 0 if success -1 if error 66 | */ 67 | int close(); 68 | 69 | /** 70 | * Send a message to HTTP client 71 | * 72 | * @param string 73 | * Message to be sent to client 74 | * @return 75 | * 0 if success -1 if error 76 | */ 77 | void sendHttpMessage(std::string message); 78 | 79 | /** 80 | * @brief setSocketClient 81 | * Define client socket for this object 82 | * @param clientSocket 83 | * client socket 84 | */ 85 | void setSocketClient(QTcpSocket * clientSocket); 86 | 87 | void writeStringToSocket(std::string message); 88 | 89 | void writeByteArrayToSocket(const QByteArray array); 90 | 91 | void flush(); 92 | 93 | void writeCharToSocket(char * data,int size); 94 | 95 | private: 96 | 97 | /** 98 | * @brief clientSocket 99 | * client socket 100 | */ 101 | QTcpSocket* clientSocket; 102 | }; 103 | 104 | #endif // CLIENTSOCKET_H 105 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/httpserverimpl/httpserver.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HttpServer.h 26 | 27 | Http server main process class 28 | 29 | manage incoming connections 30 | manage socket encryption for SSL socket 31 | manage process of incoming data from client socket 32 | 33 | @author Bertrand Martel 34 | @version 1.0 35 | */ 36 | #ifndef HTTPSERVER_H 37 | #define HTTPSERVER_H 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include "protocol/inter/http/httpconsumer.h" 45 | #include "protocol/http/httpdecoder.h" 46 | #include "clientSocket.h" 47 | #include "QSslCertificate" 48 | #include "QList" 49 | #include "QSslKey" 50 | #include "httpserverinter/IClientEventListener.h" 51 | #include 52 | #include "protocol/inter/http/httpframe.h" 53 | /** 54 | * @brief The HttpServer class 55 | * Http server main process class 56 | * 57 | *
    58 | *
  • manage incoming connections
  • 59 | *
  • manage socket encryption for SSL socket
  • 60 | *
  • manage process of incoming data from client socket
  • 61 | *
62 | */ 63 | class HttpServer: public QTcpServer 64 | { 65 | 66 | Q_OBJECT 67 | public: 68 | 69 | /** 70 | * @brief HttpServer 71 | * Http server build object 72 | * @param parent 73 | */ 74 | HttpServer(QObject * parent = 0); 75 | 76 | /** 77 | * @brief socketClientList 78 | * socket client list 79 | */ 80 | static std::map socketClientList; 81 | 82 | ~HttpServer(); 83 | 84 | /** 85 | * @brief HttpServer::addClientEventListener 86 | * add a client event listener to list 87 | * @param clientListener 88 | * client listener 89 | */ 90 | void addClientEventListener(IClientEventListener * clientListener); 91 | 92 | /** 93 | * @brief HttpServer::setSSL 94 | * set Http server to secured Http server 95 | * @param use_ssl 96 | */ 97 | void setSSL(bool use_ssl); 98 | 99 | /** 100 | * @brief HttpServer::setPublicCert 101 | * set public server cert 102 | * @param cert 103 | * public certificate 104 | */ 105 | void setPublicCert(QSslCertificate cert); 106 | 107 | /** 108 | * @brief HttpServer::setCaCert 109 | * set certification authoritycert 110 | * @param cert 111 | * certification authority cert 112 | */ 113 | void setCaCert(QList< QSslCertificate > cert); 114 | 115 | /** 116 | * @brief HttpServer::setPrivateCert 117 | * set private certificate 118 | * @param cert 119 | * private certificate 120 | */ 121 | void setPrivateCert(QSslKey key); 122 | 123 | 124 | /** 125 | * @brief HttpServer::containsHttpProcessedFrames 126 | * check if http frame list buffer already contains finished http processed frame or no 127 | * @param frameList 128 | * list of http frames 129 | * @return 130 | */ 131 | bool containsHttpProcessedFrames(std::vector frameList); 132 | 133 | /** 134 | * @brief HttpServer::set_debug 135 | * activate / desactivate debug 136 | * @param use_ssl 137 | */ 138 | void set_debug(bool state); 139 | 140 | private slots: 141 | 142 | /** 143 | * @brief incomingData 144 | * slot called when data comes from client socket 145 | */ 146 | void incomingData(); 147 | 148 | /** 149 | * @brief handleNewConnection 150 | * called when a new connection pop up 151 | */ 152 | void handleNewConnection(); 153 | 154 | /** 155 | * @brief slot_connected 156 | * called when a socket connect successfully to server 157 | */ 158 | void slot_connected (); 159 | 160 | /** 161 | * @brief slot_disconnected 162 | * called when a socket disconnect from server 163 | */ 164 | void slot_disconnected (); 165 | 166 | void ready(); 167 | 168 | void slot_error (QAbstractSocket::SocketError err); 169 | void slot_hostFound (); 170 | void slot_proxyAuthenticationRequired (const QNetworkProxy &, QAuthenticator *); 171 | void slot_stateChanged (QAbstractSocket::SocketState state); 172 | 173 | //bunch of slots used to check different state of SSL encryption process through QTNetwork processing 174 | void slot_encrypted (); 175 | void slot_encryptedBytesWritten (qint64 written); 176 | void slot_modeChanged (QSslSocket::SslMode mode); 177 | void slot_peerVerifyError (const QSslError &); 178 | void slot_sslErrors (const QList &); 179 | 180 | private: 181 | 182 | /** 183 | * @brief nextPendingConnection 184 | * overidde of next pending connection for queuing socket in a list 185 | * @return 186 | */ 187 | QSslSocket* nextPendingConnection(); 188 | 189 | /** 190 | * @brief incomingConnection 191 | * new connection has come 192 | * @param socketDescriptor 193 | */ 194 | void incomingConnection(int socketDescriptor); 195 | 196 | /** 197 | * @brief HttpServer::startServerEncryption 198 | * add respective certificates for SSL encryption 199 | * 200 | * @param clientSocket 201 | * ssl client socket 202 | */ 203 | void startServerEncryption(QSslSocket* clientSocket); 204 | 205 | /** 206 | * @brief HttpServer::connectSocketSignals 207 | * connect signals to slots : we take the maximum of slots here to manage errors quickly 208 | * @param clientSocket 209 | * client socket incoming 210 | */ 211 | void connectSocketSignals(QSslSocket* clientSocket); 212 | 213 | /** 214 | * @brief HttpServer::closeClientSocket 215 | * close client socket function 216 | * @param socket 217 | * client socket 218 | */ 219 | void closeClientSocket(QSslSocket* socket); 220 | 221 | //ssl certs used to encrypt ssl socket 222 | 223 | /** 224 | * @brief localCertificate 225 | * public certificate 226 | */ 227 | QSslCertificate localCertificate; 228 | 229 | /** 230 | * @brief caCertificate 231 | * certification authority list of certificates 232 | */ 233 | QList< QSslCertificate > caCertificate; 234 | 235 | /** 236 | * @brief keyCertificate 237 | * private certificate 238 | */ 239 | QSslKey keyCertificate; 240 | 241 | /** 242 | * @brief consumer 243 | * http consumer used to retrieve chunk of http frames 244 | */ 245 | httpconsumer * consumer; 246 | 247 | /** 248 | * @brief decoder 249 | * http decoder used to decode http frames streaming 250 | */ 251 | httpdecoder decoder; 252 | 253 | /** 254 | * @brief debug 255 | * debug state for Http server 256 | */ 257 | bool debug; 258 | 259 | /** 260 | * @brief ssl 261 | * define if Http protocol must use encryption or not 262 | */ 263 | bool ssl; 264 | 265 | /** 266 | * @brief clientEventListenerList 267 | * list of client event listener 268 | */ 269 | std::vector clientEventListenerList; 270 | 271 | /** 272 | * @brief queue 273 | * used to store connection in a list 274 | */ 275 | QQueue queue; 276 | }; 277 | 278 | 279 | #endif // HTTPSERVER_H 280 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/httpserverinter/IClientEventListener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IClientEventListener.h 26 | 27 | Define all client socket event that can happen and that will pop event in class that will inherit this one 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef ICLIENTEVENTLISTENER_H 33 | #define ICLIENTEVENTLISTENER_H 34 | 35 | #include "IHttpClient.h" 36 | #include "string" 37 | #include "protocol/inter/http/IhttpFrame.h" 38 | 39 | /** 40 | * @brief The IClientEventListener class 41 | * Client Socket event listener template class 42 | */ 43 | class IClientEventListener 44 | { 45 | 46 | public : 47 | 48 | /** 49 | * called when an http request has been received from client 50 | * 51 | * @param client 52 | * client object 53 | * @param message 54 | * message delivered 55 | */ 56 | virtual void onHttpRequestReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address)= 0; 57 | 58 | /** 59 | * called when an http response has been received from client 60 | * 61 | * @param client 62 | * client object 63 | * @param message 64 | * message delivered 65 | */ 66 | virtual void onHttpResponseReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address)= 0; 67 | 68 | }; 69 | 70 | 71 | #endif // ICLIENTEVENTLISTENER_H 72 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/httpserverinter/IHttpClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IWebsocketClient.h 26 | 27 | Define generic template for http client socket 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef IHTTPCLIENT_H 33 | #define IHTTPCLIENT_H 34 | #include "string" 35 | #include "QByteArray" 36 | 37 | class IHttpClient 38 | { 39 | 40 | public : 41 | /** 42 | * Send http message to client 43 | * 44 | * @param string 45 | * Message to be sent to client 46 | * @return 47 | * 0 if success -1 if error 48 | */ 49 | virtual void sendHttpMessage(std::string message)= 0; 50 | 51 | virtual void writeStringToSocket(std::string message)=0; 52 | 53 | virtual void writeByteArrayToSocket(const QByteArray array)=0; 54 | 55 | virtual void flush()=0; 56 | 57 | virtual void writeCharToSocket(char * data,int size)=0; 58 | 59 | }; 60 | 61 | #endif // IHTTPCLIENT_H 62 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/http/httpconstants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpconstants.h 26 | HTTP constants file 27 | Regroup all constants used for HTTP parser 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPCONSTANTS_H 33 | #define HTTPCONSTANTS_H 34 | #include "vector" 35 | #include "string" 36 | 37 | /** 38 | * @brief The httpconstants class 39 | * store HTTP parser constants 40 | */ 41 | class httpconstants 42 | { 43 | 44 | public: 45 | 46 | #define HTTP_HEADERS_CONTENT_LENGTH "Content-Length" 47 | 48 | #define HTTP_METHOD_GET "GET" 49 | 50 | #define HTTP_METHOD_POST "POST" 51 | 52 | #define HTTP_METHOD_PUT "PUT" 53 | 54 | #define HTTP_METHOD_DELETE "DELETE" 55 | 56 | // struct for status code / status code phrase 57 | typedef struct statusCodeStruct 58 | { 59 | int code_value; 60 | std::string code_phrase; 61 | 62 | statusCodeStruct(int code_value,std::string code_phrase) : 63 | code_value(code_value), code_phrase(code_phrase){} 64 | } statusCode; 65 | 66 | /** 67 | * @brief http_status_code_list 68 | * list of status code / code phrase 69 | */ 70 | static std::vector http_status_code_list; 71 | 72 | /** 73 | * @brief static_init 74 | * list of status code is statically stored : this must be called only once to avoid doublons (TODO : check if there is another way) 75 | */ 76 | static void static_init(){ 77 | http_status_code_list.push_back(statusCodeStruct(100, "Continue" )); 78 | http_status_code_list.push_back(statusCodeStruct(101, "Switching Protocols" )); 79 | http_status_code_list.push_back(statusCodeStruct(200, "OK" )); 80 | http_status_code_list.push_back(statusCodeStruct(201, "Created" )); 81 | http_status_code_list.push_back(statusCodeStruct(202, "Accepted" )); 82 | http_status_code_list.push_back(statusCodeStruct(203, "Non-Authoritative Information" )); 83 | http_status_code_list.push_back(statusCodeStruct(204, "No Content" )); 84 | http_status_code_list.push_back(statusCodeStruct(205, "Reset Content" )); 85 | http_status_code_list.push_back(statusCodeStruct(206, "Partial Content" )); 86 | http_status_code_list.push_back(statusCodeStruct(300, "Multiple Choices" )); 87 | http_status_code_list.push_back(statusCodeStruct(301, "Moved Permanently" )); 88 | http_status_code_list.push_back(statusCodeStruct(302, "Found" )); 89 | http_status_code_list.push_back(statusCodeStruct(303, "See Other" )); 90 | http_status_code_list.push_back(statusCodeStruct(304, "Not Modified" )); 91 | http_status_code_list.push_back(statusCodeStruct(305, "Use Proxy" )); 92 | http_status_code_list.push_back(statusCodeStruct(307, "Temporary Redirect" )); 93 | http_status_code_list.push_back(statusCodeStruct(400, "Bad Request" )); 94 | http_status_code_list.push_back(statusCodeStruct(401, "Unauthorized" )); 95 | http_status_code_list.push_back(statusCodeStruct(402, "Payment Required" )); 96 | http_status_code_list.push_back(statusCodeStruct(403, "Forbidden" )); 97 | http_status_code_list.push_back(statusCodeStruct(404, "Not Found" )); 98 | http_status_code_list.push_back(statusCodeStruct(405, "Method Not Allowed" )); 99 | http_status_code_list.push_back(statusCodeStruct(406, "Not Acceptable" )); 100 | http_status_code_list.push_back(statusCodeStruct(407, "Proxy Authentication Required" )); 101 | http_status_code_list.push_back(statusCodeStruct(408, "Request Time-out" )); 102 | http_status_code_list.push_back(statusCodeStruct(409, "Conflict" )); 103 | http_status_code_list.push_back(statusCodeStruct(410, "Gone" )); 104 | http_status_code_list.push_back(statusCodeStruct(411, "Length Required" )); 105 | http_status_code_list.push_back(statusCodeStruct(412, "Precondition Failed" )); 106 | http_status_code_list.push_back(statusCodeStruct(413, "Request Entity Too Large" )); 107 | http_status_code_list.push_back(statusCodeStruct(414, "Request-URI Too Large" )); 108 | http_status_code_list.push_back(statusCodeStruct(415, "Unsupported Media Type" )); 109 | http_status_code_list.push_back(statusCodeStruct(416, "Requested range not satisfiable" )); 110 | http_status_code_list.push_back(statusCodeStruct(417, "Expectation Failed" )); 111 | http_status_code_list.push_back(statusCodeStruct(500, "Internal Server Error" )); 112 | http_status_code_list.push_back(statusCodeStruct(501, "Not Implemented" )); 113 | http_status_code_list.push_back(statusCodeStruct(502, "Bad Gateway" )); 114 | http_status_code_list.push_back(statusCodeStruct(503, "Service Unavailable" )); 115 | http_status_code_list.push_back(statusCodeStruct(504, "Gateway Time-out" )); 116 | http_status_code_list.push_back(statusCodeStruct(505, "HTTP Version not supported" )); 117 | } 118 | }; 119 | 120 | #endif // HTTPCONSTANTS_H 121 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/http/httpdecoder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HttpDecoder.h 26 | HTTP Decoder main class 27 | Will decode according to CRLF presence or add data to http consumer buffer 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPDECODER_H 33 | #define HTTPDECODER_H 34 | 35 | #include "protocol/inter/http/httpconsumer.h" 36 | #include "QByteArray" 37 | 38 | /** 39 | * @brief The HttpDecoder class 40 | * 41 | * Http decoder main input class 42 | */ 43 | class httpdecoder 44 | { 45 | 46 | public : 47 | 48 | httpdecoder(); 49 | 50 | /** 51 | * @brief httpDecode 52 | * http decoder 53 | * 54 | * @param consumer 55 | * http client consumer featuring connection monitoring 56 | * @param data 57 | * non-blocking or blocking data stream 58 | */ 59 | void httpdecode(httpconsumer * consumer,QByteArray* data); 60 | 61 | }; 62 | 63 | #endif // HTTPDECODER_H 64 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/http/httpdecoder_global.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpdecoder_global.h 26 | This will make access this library to QLibrary (no need to access header and lib) 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef HTTPDECODER_GLOBAL_H 32 | #define HTTPDECODER_GLOBAL_H 33 | 34 | #include 35 | 36 | #if defined(HTTPDECODER_LIBRARY) 37 | # define HTTPDECODERSHARED_EXPORT Q_DECL_EXPORT 38 | #else 39 | # define HTTPDECODERSHARED_EXPORT Q_DECL_IMPORT 40 | #endif 41 | 42 | #endif // HTTPDECODER_GLOBAL_H 43 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/http/httpparser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpparser.h 26 | HTTP Parser 27 | Will parse streaming data through parseHttp() method 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPPARSER_H 33 | #define HTTPPARSER_H 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "protocol/inter/http/httpconsumer.h" 39 | 40 | /** 41 | * @brief The HttpParser class 42 | * Main HTTP Parser
43 | * Will parse streaming data 44 | */ 45 | class httpparser 46 | { 47 | 48 | public: 49 | httpparser(); 50 | 51 | /** 52 | * @brief parseHttp 53 | * parse streaming data 54 | * 55 | * @param data 56 | * streaming data 57 | */ 58 | void parseHttp(QByteArray* data,httpconsumer * consumer); 59 | 60 | /** 61 | * @brief setDebug 62 | * set debug mode for http parser 63 | * @param debug 64 | */ 65 | void setDebug(bool debug); 66 | 67 | /** 68 | * @brief getHeaders 69 | * retrieve http headers 70 | * @return 71 | */ 72 | std::map< std::string,std::string > *getHeaders(); 73 | 74 | private: 75 | 76 | /** 77 | * @brief isMethod 78 | * check if input data is a valid HTTP rest method 79 | * 80 | * @param data 81 | * data to be tested 82 | * @return 83 | * true if data is valid REST HTTP method 84 | */ 85 | bool isMethod(std::string data); 86 | 87 | /** 88 | * @brief isStatusNum 89 | * check if input data is a valid HTTP status code 90 | * @param data 91 | * data to be tested 92 | * @return 93 | * true if data is valid HTTP status code 94 | */ 95 | bool isStatusNum(std::string data); 96 | 97 | /** 98 | * @brief debug 99 | * debug activation 100 | */ 101 | bool debug; 102 | }; 103 | 104 | #endif // HTTPPARSER_H 105 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/http/httpstates.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpstates.h 26 | HTTP parser states 27 | Regroup all states present in http parser 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPSTATES_H 33 | #define HTTPSTATES_H 34 | 35 | #define HTTP_STATE_INIT 0 36 | 37 | #define HTTP_STATE_VERSION 1 38 | 39 | #define HTTP_STATE_HEADERS 2 40 | 41 | #define HTTP_STATE_BODY 3 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/inter/http/IhttpFrame.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | IHttpFrame.h 26 | HTTP frame template 27 | Regroup all http metadata for one http frame 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef IHTTPFRAME_H 33 | #define IHTTPFRAME_H 34 | 35 | #include "string" 36 | #include "map" 37 | 38 | /** 39 | * @brief The IHttpFrame class 40 | * Interface defining all http metadata decoded from http decoder 41 | * 42 | */ 43 | class Ihttpframe{ 44 | 45 | public: 46 | /** 47 | * @brief getUri 48 | * retrieve HTTP uri 49 | * @return 50 | */ 51 | virtual std::string getUri()= 0; 52 | 53 | /** 54 | * @brief setUri 55 | * set http uri value 56 | * @param uri 57 | */ 58 | virtual void setUri(std::string uri)= 0; 59 | 60 | /** 61 | * @brief getMethod 62 | * retrieve HTTP method 63 | * @return 64 | */ 65 | virtual std::string getMethod()= 0; 66 | 67 | /** 68 | * @brief setMethod 69 | * set http method 70 | * @param method 71 | */ 72 | virtual void setMethod(std::string method)= 0; 73 | 74 | /** 75 | * @brief getBodyLength 76 | * retrieve length of body 77 | * @return 78 | */ 79 | virtual std::string getBody()= 0; 80 | 81 | /** 82 | * @brief setBody 83 | * set http body value 84 | * @param body 85 | */ 86 | virtual void setBody(std::string body)= 0; 87 | 88 | /** 89 | * @brief getQueryString 90 | * retrieve query string value 91 | * @return 92 | */ 93 | virtual std::string getQueryString()= 0; 94 | 95 | /** 96 | * @brief setQueryString 97 | * set http query string value 98 | * @param querystring 99 | */ 100 | virtual void setQueryString(std::string querystring)= 0; 101 | 102 | /** 103 | * @brief getStatusCode 104 | * retrieve status code 105 | * @return 106 | */ 107 | virtual int getStatusCode()= 0; 108 | 109 | /** 110 | * @brief setStatusCode 111 | * set status code value 112 | * @param statusCode 113 | */ 114 | virtual void setStatusCode(int statusCode)= 0; 115 | 116 | /** 117 | * @brief getHeaders 118 | * retrieve http headers 119 | * @return 120 | */ 121 | virtual std::map< std::string,std::string > getHeaders()= 0; 122 | 123 | /** 124 | * @brief httpConsumer::getProcessState 125 | * retrieve true if all data has been processed in current buffer 126 | * @return 127 | * 128 | */ 129 | virtual bool isFinishedProcessing()= 0; 130 | 131 | /** 132 | * @brief setFinishedProcessing 133 | * set processing frame state 134 | * @param processing 135 | */ 136 | virtual void setFinishedProcessing(bool processing)= 0; 137 | 138 | }; 139 | 140 | #endif // IHTTPFRAME_H 141 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/inter/http/httpconsumer.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | httpconsumer.cpp 26 | HTTP Consumer client 27 | This object permits to store http life cycle into your own design and monitor your parsing in a blocking or non-blocking socket configuration 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HTTPCONSUMER_H 33 | #define HTTPCONSUMER_H 34 | 35 | #include "string" 36 | #include "QByteArray" 37 | #include "map" 38 | #include "IhttpFrame.h" 39 | #include "vector" 40 | #include "httpframe.h" 41 | 42 | /** 43 | * @brief httpConsumer::httpConsumer 44 | * Consumer client of http decoder
45 | * This object permits to store http life cycle into your own design and monitor your parsing in a blocking or non-blocking socket configuration 46 | */ 47 | class httpconsumer 48 | { 49 | public: 50 | 51 | ~httpconsumer(); 52 | 53 | /** 54 | * @brief httpConsumer::httpConsumer 55 | * Consumer client of http decoder
56 | * This object permits to store http life cycle into your own design and monitor your parsing in a blocking or non-blocking socket configuration 57 | */ 58 | httpconsumer(); 59 | 60 | /** 61 | * @brief httpConsumer::clearBuffer 62 | * clear current buffer 63 | */ 64 | void clearBuffer(); 65 | 66 | /** 67 | * @brief httpConsumer::appendToBuffer 68 | * append some data to buffer 69 | *@param data 70 | * data to be appended 71 | * @return 72 | * pointer to data 73 | */ 74 | int appendToBuffer(QByteArray* data); 75 | 76 | /** 77 | * @brief httpConsumer::getBuffer 78 | * retrieve current buffer 79 | *@return 80 | */ 81 | QByteArray getBuffer(); 82 | 83 | /** 84 | * @brief httpConsumer::getProcessState 85 | * retrieve true if all data has been processed in current buffer 86 | * @return 87 | * 88 | */ 89 | bool isFinishedProcessing(); 90 | 91 | /** 92 | * @brief setFinishedProcessing 93 | * set processing frame state 94 | * @param processing 95 | */ 96 | void setFinishedProcessing(bool processing); 97 | 98 | /** 99 | * @brief setDebug 100 | * set debug mode for consumer 101 | * @param debug 102 | */ 103 | void setDebug(bool debug); 104 | 105 | /** 106 | * @brief bodyIndex 107 | * index of body in buffer element 108 | */ 109 | int getBodyIndex(); 110 | 111 | /** 112 | * @brief setBodyIndex 113 | * set body index 114 | * @param bodyIndexArg 115 | */ 116 | void setBodyIndex(int bodyIndexArg); 117 | 118 | /** 119 | * @brief bodyProcess 120 | * get to know if HTTP body is to be parsed or not 121 | */ 122 | bool getBodyProcess(); 123 | 124 | /** 125 | * @brief setBodyProcess 126 | * set HTTP body parsing state 127 | * @param processArg 128 | */ 129 | void setBodyProcess(bool processArg); 130 | 131 | /** 132 | * @brief bodyLength 133 | * length of body 134 | */ 135 | int getBodyLength(); 136 | 137 | /** 138 | * @brief setBodyLength 139 | * set body length 140 | * @param length 141 | */ 142 | void setBodyLength(int length); 143 | 144 | /** 145 | * @brief httpState 146 | * http parser current state 147 | */ 148 | int getHttpState(); 149 | 150 | /** 151 | * @brief setHttpState 152 | * set http parser state 153 | * @param http_state 154 | */ 155 | void setHttpState(int http_state); 156 | 157 | /** 158 | * @brief isDebug 159 | * debug state 160 | * @return 161 | */ 162 | bool isDebug(); 163 | 164 | /** 165 | * @brief getHttpFrameList 166 | * retrieve http frame object list 167 | * @return 168 | */ 169 | std::vector getHttpFrameList(); 170 | 171 | /** 172 | * @brief httpConsumer::addNewHttpFrame 173 | * add a new http frame in the list 174 | * @param frame 175 | */ 176 | void addNewHttpFrame(httpframe frame); 177 | 178 | /** 179 | * @brief getCurrentHttpFrame 180 | * retrieve current http frame object 181 | * @return 182 | */ 183 | httpframe *getCurrentHttpFrame(); 184 | 185 | /** 186 | * @brief setHttpFrameList 187 | * set http frame list object 188 | * @param list 189 | * pointer to vector of IHttp frames 190 | */ 191 | void setHttpFrameList(std::vector list); 192 | 193 | private: 194 | 195 | /** 196 | * @brief buffer 197 | * buffer used to store current unfinished http stream data (unfinished => not terminating with carriage return) 198 | */ 199 | QByteArray buffer; 200 | 201 | /** 202 | * @brief bodyIndex 203 | * index of body in buffer element 204 | */ 205 | int bodyIndex; 206 | 207 | /** 208 | * @brief bodyProcess 209 | * get to know if HTTP body is to be parsed or not 210 | */ 211 | bool bodyProcess; 212 | 213 | /** 214 | * @brief bodyLength 215 | * length of body 216 | */ 217 | int bodyLength; 218 | 219 | /** 220 | * @brief httpState 221 | * http parser current state 222 | */ 223 | int httpState; 224 | 225 | /** 226 | * @brief processFrame 227 | * indicate that HTTP frame has finished processing 228 | */ 229 | bool finishedProcessing; 230 | 231 | /** 232 | * @brief debug 233 | * debug activation 234 | */ 235 | bool debug; 236 | 237 | /** 238 | * @brief httpFrameList 239 | * list of http frames 240 | */ 241 | std::vector httpFrameList; 242 | 243 | }; 244 | 245 | #endif // HTTPCONSUMER_H 246 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/protocol/inter/http/httpframe.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #ifndef HTTPFRAME_H 25 | #define HTTPFRAME_H 26 | 27 | #include "IhttpFrame.h" 28 | 29 | class httpframe : public Ihttpframe 30 | { 31 | public: 32 | httpframe(); 33 | 34 | ~httpframe(); 35 | 36 | /** 37 | * @brief getUri 38 | * retrieve HTTP uri 39 | * @return 40 | */ 41 | std::string getUri(); 42 | 43 | /** 44 | * @brief setUri 45 | * set http uri value 46 | * @param uri 47 | */ 48 | void setUri(std::string uri); 49 | 50 | /** 51 | * @brief getMethod 52 | * retrieve HTTP method 53 | * @return 54 | */ 55 | std::string getMethod(); 56 | 57 | /** 58 | * @brief setMethod 59 | * set http method 60 | * @param method 61 | */ 62 | void setMethod(std::string method); 63 | 64 | /** 65 | * @brief getBodyLength 66 | * retrieve length of body 67 | * @return 68 | */ 69 | std::string getBody(); 70 | 71 | /** 72 | * @brief setBody 73 | * set http body value 74 | * @param body 75 | */ 76 | void setBody(std::string body); 77 | 78 | /** 79 | * @brief getQueryString 80 | * retrieve query string value 81 | * @return 82 | */ 83 | std::string getQueryString(); 84 | 85 | /** 86 | * @brief setQueryString 87 | * set http query string value 88 | * @param querystring 89 | */ 90 | void setQueryString(std::string querystring); 91 | 92 | /** 93 | * @brief getStatusCode 94 | * retrieve status code 95 | * @return 96 | */ 97 | int getStatusCode(); 98 | 99 | /** 100 | * @brief setStatusCode 101 | * set status code value 102 | * @param statusCode 103 | */ 104 | void setStatusCode(int statusCode); 105 | 106 | /** 107 | * @brief getHeaders 108 | * retrieve http headers 109 | * @return 110 | */ 111 | std::map< std::string,std::string > getHeaders(); 112 | 113 | /** 114 | * @brief httpConsumer::getProcessState 115 | * retrieve true if all data has been processed in current buffer 116 | * @return 117 | * 118 | */ 119 | bool isFinishedProcessing(); 120 | 121 | /** 122 | * @brief setFinishedProcessing 123 | * set processing frame state 124 | * @param processing 125 | */ 126 | void setFinishedProcessing(bool processing); 127 | 128 | /** 129 | * @brief setHeaders 130 | * set http headers 131 | * @param header 132 | */ 133 | void setHeaders(std::map header); 134 | 135 | private : 136 | 137 | /** 138 | * @brief querystring 139 | * HTTP querystring 140 | */ 141 | std::string querystring; 142 | 143 | /** 144 | * @brief uri 145 | * uri of HTTP frame 146 | */ 147 | std::string uri; 148 | 149 | /** 150 | * @brief method 151 | * method of HTTP frame 152 | */ 153 | std::string method; 154 | 155 | /** 156 | * @brief body 157 | * body of HTTP frame 158 | */ 159 | std::string body; 160 | 161 | 162 | /** 163 | * @brief statusNum 164 | * status code of HTTP frame 165 | */ 166 | int statusCode; 167 | 168 | 169 | /** 170 | * @brief headers 171 | * HTTP headers 172 | */ 173 | std::map headers; 174 | 175 | /** 176 | * @brief processFrame 177 | * indicate that HTTP frame has finished processing 178 | */ 179 | bool finishedProcessing; 180 | }; 181 | 182 | #endif // HTTPFRAME_H 183 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/libs/utils/stringutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | stringutils.h 3 | Utility funcions for http parser 4 | 5 | @author Bertrand Martel 6 | @version 1.0 7 | */ 8 | #ifndef STRINGUTILS_H 9 | #define STRINGUTILS_H 10 | 11 | #include "stringutils.h" 12 | #include "vector" 13 | #include "string" 14 | 15 | /** 16 | * @brief The stringutils class 17 | * String utility functions 18 | */ 19 | class stringutils 20 | { 21 | public: 22 | 23 | /** 24 | * @brief split 25 | * split a string with a character delimiter 26 | * @param s 27 | * string to split 28 | * @param delim 29 | * character delimiter 30 | * @return 31 | * vector of splitted string 32 | */ 33 | static std::vector split(std::string s, char delim); 34 | 35 | /** 36 | * @brief isNum 37 | * check if char * is numeric data 38 | * @param s 39 | * char * input 40 | * @return 41 | * true if data is numeric 42 | */ 43 | static bool isNum(char *s); 44 | 45 | }; 46 | 47 | #endif // STRINGUTILS_H 48 | -------------------------------------------------------------------------------- /digest-auth-session-lib/release/utils/stringutil.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGUTIL_H 2 | #define STRINGUTIL_H 3 | 4 | #include "string" 5 | #include 6 | 7 | class stringutil 8 | { 9 | public: 10 | 11 | static std::string replaceAll(std::string str, const std::string& from, const std::string& to); 12 | 13 | static std::vector split(const std::string &s, char delim, std::vector &elems); 14 | 15 | static std::vector split(const std::string &s, char delim); 16 | }; 17 | 18 | #endif // STRINGUTIL_H 19 | -------------------------------------------------------------------------------- /digest-auth-session-lib/utils/stringutil.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | stringutil.cpp 3 | 4 | String functions 5 | 6 | @author Bertrand Martel 7 | @version 1.0 8 | */ 9 | #include "stringutil.h" 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | std::string stringutil::replaceAll(std::string str, const std::string& from, const std::string& to) { 16 | size_t start_pos = 0; 17 | while((start_pos = str.find(from, start_pos)) != std::string::npos) { 18 | str.replace(start_pos, from.length(), to); 19 | start_pos += to.length(); // Handles case where 'to' is a substring of 'from' 20 | } 21 | return str; 22 | } 23 | 24 | std::vector stringutil::split(const std::string &s, char delim, std::vector &elems) { 25 | stringstream ss(s); 26 | string item; 27 | while (getline(ss, item, delim)) { 28 | elems.push_back(item); 29 | } 30 | return elems; 31 | } 32 | 33 | std::vector stringutil::split(const std::string &s, char delim) { 34 | vector elems; 35 | split(s, delim, elems); 36 | return elems; 37 | } 38 | -------------------------------------------------------------------------------- /digest-auth-session-lib/utils/stringutil.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGUTIL_H 2 | #define STRINGUTIL_H 3 | 4 | #include "string" 5 | #include 6 | 7 | class stringutil 8 | { 9 | public: 10 | 11 | static std::string replaceAll(std::string str, const std::string& from, const std::string& to); 12 | 13 | static std::vector split(const std::string &s, char delim, std::vector &elems); 14 | 15 | static std::vector split(const std::string &s, char delim); 16 | }; 17 | 18 | #endif // STRINGUTIL_H 19 | -------------------------------------------------------------------------------- /digest-auth-session-test/ClientSocketHandler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | ClientSocketHandler.cpp 26 | Client socket managing event handler 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #include "ClientSocketHandler.h" 32 | 33 | #include "httpserverinter/IHttpClient.h" 34 | #include "DigestManager.h" 35 | #include "iostream" 36 | #include "string.h" 37 | #include "protocol/inter/http/IhttpFrame.h" 38 | #include "sstream" 39 | 40 | using namespace std; 41 | 42 | ClientSocketHandler::ClientSocketHandler(DigestManager* digest_manager) 43 | { 44 | this->digest_manager=digest_manager; 45 | 46 | unauthorized_page = QString("HTTP/1.1 401 Unauthorized\r\nContent-Type: text/html\r\nContent-Length: 297\r\n\r\n\r\n" 48 | + "\r\n" 49 | + "\r\n" 50 | + "Error\r\n" 51 | + " \r\n" 52 | + "\r\n" 53 | + "

401 Unauthorized.

\r\n" 54 | + "\r\n"; 55 | 56 | internal_error_page = QString("HTTP/1.1 500 Internal Server Error\r\nContent-Type: text/html\r\nContent-Length: 306\r\n\r\n\r\n" 58 | + "\r\n" 59 | + "\r\n" 60 | + "Error\r\n" 61 | + " \r\n" 62 | + "\r\n" 63 | + "

500 Internal Server Error.

\r\n" 64 | + "\r\n"; 65 | 66 | login_success_page=QString("HTTP/1.1 200 Ok\r\nContent-Type: text/html\r\nContent-Length: 14\r\n\r\n

SUCCESS

").toStdString(); 67 | } 68 | 69 | ClientSocketHandler::~ClientSocketHandler() 70 | { 71 | } 72 | 73 | /** 74 | * called when an http response has been received from client 75 | * 76 | * @param client 77 | * client object 78 | * @param message 79 | * message delivered 80 | */ 81 | void ClientSocketHandler::onHttpResponseReceived(IHttpClient &client,Ihttpframe * frame,std::string peer_address){ 82 | } 83 | 84 | /** 85 | * called when an http response has been received from client 86 | * 87 | * @param client 88 | * client object 89 | * @param message 90 | * message delivered 91 | */ 92 | void ClientSocketHandler::onHttpRequestReceived(IHttpClient &client,Ihttpframe * frame,std::string peer_address){ 93 | 94 | cout << "Http request received for client " << peer_address << endl; 95 | 96 | if (strcmp(frame->getMethod().data(),"GET")==0 && strcmp(frame->getUri().data(),"/login")==0){ 97 | 98 | DigestInfo digest_info = digest_manager->process_digest(frame->getMethod(),frame->getUri(),frame->getHeaders(),"akinaru_realm"); 99 | 100 | cout << "Receive digest response with status code : " << digest_info.get_status_code() << endl; 101 | 102 | std::string content = ""; 103 | stringstream contentLength; 104 | 105 | if (digest_info.get_status_code()==401){ 106 | 107 | content = unauthorized_page; 108 | contentLength << content.size(); 109 | 110 | string response = QString("HTTP/1.1 401 Unauthorized\r\n").toStdString() + 111 | "Content-Type: text/html\r\nContent-Length: " + contentLength.str() + "\r\n"; 112 | 113 | if (digest_info.get_headers()->size()>0){ 114 | 115 | for (std::map::iterator iter=digest_info.get_headers()->begin(); iter!=digest_info.get_headers()->end(); ++iter){ 116 | response+=iter->first+": " +iter->second + "\r\n"; 117 | } 118 | } 119 | 120 | response+=QString("\r\n").toStdString() + content; 121 | 122 | cout << "Sending response with status code 401 Unauthorized" << endl; 123 | 124 | client.sendHttpMessage(response); 125 | } 126 | else if (digest_info.get_status_code()==500){ 127 | 128 | content = internal_error_page; 129 | contentLength << content.size(); 130 | 131 | string response = QString("HTTP/1.1 500 Internal Server Error\r\n").toStdString() + 132 | "Content-Type: text/html\r\nContent-Length: " + contentLength.str() + "\r\n"; 133 | 134 | if (digest_info.get_headers()->size()>0){ 135 | for (std::map::iterator it=digest_info.get_headers()->begin(); it!=digest_info.get_headers()->end(); ++it) 136 | response+=it->first+": " +it->second + "\r\n"; 137 | } 138 | 139 | response+=QString("\r\n").toStdString() + content; 140 | 141 | cout << "Sending response with status code 500 Internal Server Error" << endl; 142 | 143 | client.sendHttpMessage(response); 144 | } 145 | else if (digest_info.get_status_code()==200){ 146 | 147 | content = login_success_page; 148 | contentLength << content.size(); 149 | 150 | string response = QString("HTTP/1.1 200 OK\r\n").toStdString() + 151 | "Content-Type: text/html\r\nContent-Length: " + contentLength.str() + "\r\n"; 152 | 153 | if (digest_info.get_headers()->size()>0){ 154 | for (std::map::iterator it=digest_info.get_headers()->begin(); it!=digest_info.get_headers()->end(); ++it) 155 | response+=it->first+": " +it->second + "\r\n"; 156 | } 157 | 158 | response+=QString("\r\n").toStdString() + content; 159 | 160 | cout << "Sending response with status code 200 OK" << endl; 161 | 162 | client.sendHttpMessage(response); 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /digest-auth-session-test/ClientSocketHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | ClientSocketHandler.h 26 | Client socket managing event handler 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef CLIENTSOCKETHANDLER_H 32 | #define CLIENTSOCKETHANDLER_H 33 | 34 | #include "httpserverinter/IClientEventListener.h" 35 | #include "DigestManager.h" 36 | 37 | /** 38 | * @brief The ClientSocketHandler class 39 | * Client socket managing event handler 40 | */ 41 | class ClientSocketHandler : public IClientEventListener 42 | { 43 | public: 44 | 45 | /** 46 | * @brief ClientSocketHandler 47 | * build client socket handler 48 | */ 49 | ClientSocketHandler(DigestManager * digest_manager); 50 | 51 | ~ClientSocketHandler(); 52 | 53 | /** 54 | * called when an http request has been received from client 55 | * 56 | * @param client 57 | * client object 58 | * @param message 59 | * message delivered 60 | */ 61 | void onHttpRequestReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address); 62 | 63 | /** 64 | * called when an http response has been received from client 65 | * 66 | * @param client 67 | * client object 68 | * @param message 69 | * message delivered 70 | */ 71 | void onHttpResponseReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address); 72 | 73 | private: 74 | DigestManager * digest_manager; 75 | 76 | std::string unauthorized_page; 77 | 78 | std::string internal_error_page; 79 | 80 | std::string login_success_page; 81 | }; 82 | 83 | #endif // CLIENTSOCKETHANDLER_H 84 | -------------------------------------------------------------------------------- /digest-auth-session-test/HashDigestListener.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HashDigestListener.cpp 26 | 27 | Listener for retrieving username / password hash from storage 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #include "HashDigestListener.h" 33 | #include "iostream" 34 | #include "QString" 35 | #include "QCryptographicHash" 36 | 37 | using namespace std; 38 | 39 | /** 40 | * @brief HashDigestListener::HashDigestListener 41 | * Build one client 42 | */ 43 | HashDigestListener::HashDigestListener(){ 44 | 45 | } 46 | 47 | HashDigestListener::~HashDigestListener(){ 48 | 49 | } 50 | 51 | /** 52 | * @brief get_hash_for_username 53 | * retrieve hash in database or in your configuration for specified username and realm 54 | * @return 55 | */ 56 | std::string HashDigestListener::get_hash_for_username(std::string username,std::string realm,digest_algorithm algo){ 57 | 58 | // here you look for username entry in your database and extract hash of "ALGO(username:realm:password)" 59 | // where ALGO can be MD5 or SHA1 as specified in setAlgorithm() method 60 | 61 | std::string realm_encoded = QString(QString(realm.data()).toUtf8().toBase64()).toStdString(); 62 | std::string hash2Str = QString(username.data()).toStdString() + ":" + realm_encoded + ":" + "test"; 63 | 64 | std::string hash2=""; 65 | 66 | if (algo==ALGO_MD5){ 67 | hash2 = QString(QCryptographicHash::hash(hash2Str.data(), QCryptographicHash::Md5).toHex()).toStdString(); 68 | } 69 | else if (algo==ALGO_SHA1){ 70 | hash2 = QString(QCryptographicHash::hash(hash2Str.data(), QCryptographicHash::Sha1).toHex()).toStdString(); 71 | } 72 | 73 | return hash2; 74 | } 75 | -------------------------------------------------------------------------------- /digest-auth-session-test/HashDigestListener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HashDigestListener.h 26 | 27 | Listener for retrieving username / password hash from storage 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HASHDIGESTLISTENER_H 33 | #define HASHDIGESTLISTENER_H 34 | 35 | #include "string" 36 | #include "IDigestListener.h" 37 | #include "digeststruct.h" 38 | 39 | class HashDigestListener : public IDigestListener { 40 | 41 | public: 42 | 43 | /** 44 | * @brief ClientSocketObj::ClientSocketObj 45 | * Build one client 46 | */ 47 | HashDigestListener(); 48 | 49 | ~HashDigestListener(); 50 | 51 | /** 52 | * @brief get_hash_for_username 53 | * retrieve hash in database or in your configuration for specified username and realm 54 | * @return 55 | */ 56 | std::string get_hash_for_username(std::string username,std::string realm,digest_algorithm algo); 57 | 58 | }; 59 | 60 | #endif // HASHDIGESTLISTENER_H 61 | -------------------------------------------------------------------------------- /digest-auth-session-test/Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # Makefile for building: release/digest-auth-session-test 3 | # Generated by qmake (2.01a) (Qt 4.8.4) on: Fri Sep 4 01:16:45 2015 4 | # Project: digest-auth-session-test.pro 5 | # Template: app 6 | # Command: /usr/lib/i386-linux-gnu/qt4/bin/qmake -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile digest-auth-session-test.pro 7 | ############################################################################# 8 | 9 | ####### Compiler, tools and options 10 | 11 | CC = gcc 12 | CXX = g++ 13 | DEFINES = -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED 14 | CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) 15 | CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) 16 | INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4 -I/home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-test/libs -I../digest-auth-session-lib/libs -I../digest-auth-session-lib -I. 17 | LINK = g++ 18 | LFLAGS = 19 | LIBS = $(SUBLIBS) -L/usr/lib/i386-linux-gnu -L/home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-test/../digest-auth-session-lib/libs/ -lhttpServer -lhttpdecoder -L/home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-test/../digest-auth-session-lib/release/ -ldigestauthsession -lQtNetwork -lQtCore -lpthread 20 | AR = ar cqs 21 | RANLIB = 22 | QMAKE = /usr/lib/i386-linux-gnu/qt4/bin/qmake 23 | TAR = tar -cf 24 | COMPRESS = gzip -9f 25 | COPY = cp -f 26 | SED = sed 27 | COPY_FILE = $(COPY) 28 | COPY_DIR = $(COPY) -r 29 | STRIP = strip 30 | INSTALL_FILE = install -m 644 -p 31 | INSTALL_DIR = $(COPY_DIR) 32 | INSTALL_PROGRAM = install -m 755 -p 33 | DEL_FILE = rm -f 34 | SYMLINK = ln -f -s 35 | DEL_DIR = rmdir 36 | MOVE = mv -f 37 | CHK_DIR_EXISTS= test -d 38 | MKDIR = mkdir -p 39 | 40 | ####### Output directory 41 | 42 | OBJECTS_DIR = bin/ 43 | 44 | ####### Files 45 | 46 | SOURCES = main.cpp \ 47 | ClientSocketHandler.cpp \ 48 | SslHandler.cpp \ 49 | utils/fileutils.cpp \ 50 | utils/stringutil.cpp \ 51 | HashDigestListener.cpp 52 | OBJECTS = bin/main.o \ 53 | bin/ClientSocketHandler.o \ 54 | bin/SslHandler.o \ 55 | bin/fileutils.o \ 56 | bin/stringutil.o \ 57 | bin/HashDigestListener.o 58 | DIST = /usr/share/qt4/mkspecs/common/unix.conf \ 59 | /usr/share/qt4/mkspecs/common/linux.conf \ 60 | /usr/share/qt4/mkspecs/common/gcc-base.conf \ 61 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ 62 | /usr/share/qt4/mkspecs/common/g++-base.conf \ 63 | /usr/share/qt4/mkspecs/common/g++-unix.conf \ 64 | /usr/share/qt4/mkspecs/qconfig.pri \ 65 | /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ 66 | /usr/share/qt4/mkspecs/features/qt_functions.prf \ 67 | /usr/share/qt4/mkspecs/features/qt_config.prf \ 68 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 69 | /usr/share/qt4/mkspecs/features/default_pre.prf \ 70 | /usr/share/qt4/mkspecs/features/debug.prf \ 71 | /usr/share/qt4/mkspecs/features/default_post.prf \ 72 | /usr/share/qt4/mkspecs/features/declarative_debug.prf \ 73 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ 74 | /usr/share/qt4/mkspecs/features/warn_on.prf \ 75 | /usr/share/qt4/mkspecs/features/qt.prf \ 76 | /usr/share/qt4/mkspecs/features/unix/thread.prf \ 77 | /usr/share/qt4/mkspecs/features/moc.prf \ 78 | /usr/share/qt4/mkspecs/features/resources.prf \ 79 | /usr/share/qt4/mkspecs/features/uic.prf \ 80 | /usr/share/qt4/mkspecs/features/yacc.prf \ 81 | /usr/share/qt4/mkspecs/features/lex.prf \ 82 | /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 83 | digest-auth-session-test.pro 84 | QMAKE_TARGET = digest-auth-session-test 85 | DESTDIR = release/ 86 | TARGET = release/digest-auth-session-test 87 | 88 | first: all 89 | ####### Implicit rules 90 | 91 | .SUFFIXES: .o .c .cpp .cc .cxx .C 92 | 93 | .cpp.o: 94 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 95 | 96 | .cc.o: 97 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 98 | 99 | .cxx.o: 100 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 101 | 102 | .C.o: 103 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" 104 | 105 | .c.o: 106 | $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" 107 | 108 | ####### Build rules 109 | 110 | all: Makefile $(TARGET) 111 | 112 | $(TARGET): $(OBJECTS) 113 | @$(CHK_DIR_EXISTS) release/ || $(MKDIR) release/ 114 | $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) 115 | { test -n "$(DESTDIR)" && DESTDIR="$(DESTDIR)" || DESTDIR=.; } && test $$(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $$DESTDIR" -ex quit '$(TARGET)' && test -f $(TARGET).gdb-index && objcopy --add-section '.gdb_index=$(TARGET).gdb-index' --set-section-flags '.gdb_index=readonly' '$(TARGET)' '$(TARGET)' && rm -f $(TARGET).gdb-index || true 116 | rsync -avm --include=*/ --include=*.h --exclude=* /home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-test// /home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-test/release 117 | 118 | Makefile: digest-auth-session-test.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ 119 | /usr/share/qt4/mkspecs/common/linux.conf \ 120 | /usr/share/qt4/mkspecs/common/gcc-base.conf \ 121 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ 122 | /usr/share/qt4/mkspecs/common/g++-base.conf \ 123 | /usr/share/qt4/mkspecs/common/g++-unix.conf \ 124 | /usr/share/qt4/mkspecs/qconfig.pri \ 125 | /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ 126 | /usr/share/qt4/mkspecs/features/qt_functions.prf \ 127 | /usr/share/qt4/mkspecs/features/qt_config.prf \ 128 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ 129 | /usr/share/qt4/mkspecs/features/default_pre.prf \ 130 | /usr/share/qt4/mkspecs/features/debug.prf \ 131 | /usr/share/qt4/mkspecs/features/default_post.prf \ 132 | /usr/share/qt4/mkspecs/features/declarative_debug.prf \ 133 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ 134 | /usr/share/qt4/mkspecs/features/warn_on.prf \ 135 | /usr/share/qt4/mkspecs/features/qt.prf \ 136 | /usr/share/qt4/mkspecs/features/unix/thread.prf \ 137 | /usr/share/qt4/mkspecs/features/moc.prf \ 138 | /usr/share/qt4/mkspecs/features/resources.prf \ 139 | /usr/share/qt4/mkspecs/features/uic.prf \ 140 | /usr/share/qt4/mkspecs/features/yacc.prf \ 141 | /usr/share/qt4/mkspecs/features/lex.prf \ 142 | /usr/share/qt4/mkspecs/features/include_source_dir.prf \ 143 | /usr/lib/i386-linux-gnu/libQtNetwork.prl \ 144 | /usr/lib/i386-linux-gnu/libQtCore.prl 145 | $(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile digest-auth-session-test.pro 146 | /usr/share/qt4/mkspecs/common/unix.conf: 147 | /usr/share/qt4/mkspecs/common/linux.conf: 148 | /usr/share/qt4/mkspecs/common/gcc-base.conf: 149 | /usr/share/qt4/mkspecs/common/gcc-base-unix.conf: 150 | /usr/share/qt4/mkspecs/common/g++-base.conf: 151 | /usr/share/qt4/mkspecs/common/g++-unix.conf: 152 | /usr/share/qt4/mkspecs/qconfig.pri: 153 | /usr/share/qt4/mkspecs/modules/qt_phonon.pri: 154 | /usr/share/qt4/mkspecs/features/qt_functions.prf: 155 | /usr/share/qt4/mkspecs/features/qt_config.prf: 156 | /usr/share/qt4/mkspecs/features/exclusive_builds.prf: 157 | /usr/share/qt4/mkspecs/features/default_pre.prf: 158 | /usr/share/qt4/mkspecs/features/debug.prf: 159 | /usr/share/qt4/mkspecs/features/default_post.prf: 160 | /usr/share/qt4/mkspecs/features/declarative_debug.prf: 161 | /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: 162 | /usr/share/qt4/mkspecs/features/warn_on.prf: 163 | /usr/share/qt4/mkspecs/features/qt.prf: 164 | /usr/share/qt4/mkspecs/features/unix/thread.prf: 165 | /usr/share/qt4/mkspecs/features/moc.prf: 166 | /usr/share/qt4/mkspecs/features/resources.prf: 167 | /usr/share/qt4/mkspecs/features/uic.prf: 168 | /usr/share/qt4/mkspecs/features/yacc.prf: 169 | /usr/share/qt4/mkspecs/features/lex.prf: 170 | /usr/share/qt4/mkspecs/features/include_source_dir.prf: 171 | /usr/lib/i386-linux-gnu/libQtNetwork.prl: 172 | /usr/lib/i386-linux-gnu/libQtCore.prl: 173 | qmake: FORCE 174 | @$(QMAKE) -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile digest-auth-session-test.pro 175 | 176 | dist: 177 | @$(CHK_DIR_EXISTS) bin/digest-auth-session-test1.0.0 || $(MKDIR) bin/digest-auth-session-test1.0.0 178 | $(COPY_FILE) --parents $(SOURCES) $(DIST) bin/digest-auth-session-test1.0.0/ && $(COPY_FILE) --parents SslHandler.h ClientSocketHandler.h utils/fileutils.h utils/stringutil.h HashDigestListener.h bin/digest-auth-session-test1.0.0/ && $(COPY_FILE) --parents main.cpp ClientSocketHandler.cpp SslHandler.cpp utils/fileutils.cpp utils/stringutil.cpp HashDigestListener.cpp bin/digest-auth-session-test1.0.0/ && (cd `dirname bin/digest-auth-session-test1.0.0` && $(TAR) digest-auth-session-test1.0.0.tar digest-auth-session-test1.0.0 && $(COMPRESS) digest-auth-session-test1.0.0.tar) && $(MOVE) `dirname bin/digest-auth-session-test1.0.0`/digest-auth-session-test1.0.0.tar.gz . && $(DEL_FILE) -r bin/digest-auth-session-test1.0.0 179 | 180 | 181 | clean:compiler_clean 182 | -$(DEL_FILE) $(OBJECTS) 183 | -$(DEL_FILE) -r /home/abathur/Bureau/open_source/digest-auth-session-cpp/digest-auth-session-test/release 184 | -$(DEL_FILE) *~ core *.core 185 | 186 | 187 | ####### Sub-libraries 188 | 189 | distclean: clean 190 | -$(DEL_FILE) $(TARGET) 191 | -$(DEL_FILE) Makefile 192 | 193 | 194 | check: first 195 | 196 | mocclean: compiler_moc_header_clean compiler_moc_source_clean 197 | 198 | mocables: compiler_moc_header_make_all compiler_moc_source_make_all 199 | 200 | compiler_moc_header_make_all: 201 | compiler_moc_header_clean: 202 | compiler_rcc_make_all: 203 | compiler_rcc_clean: 204 | compiler_image_collection_make_all: qmake_image_collection.cpp 205 | compiler_image_collection_clean: 206 | -$(DEL_FILE) qmake_image_collection.cpp 207 | compiler_moc_source_make_all: 208 | compiler_moc_source_clean: 209 | compiler_uic_make_all: 210 | compiler_uic_clean: 211 | compiler_yacc_decl_make_all: 212 | compiler_yacc_decl_clean: 213 | compiler_yacc_impl_make_all: 214 | compiler_yacc_impl_clean: 215 | compiler_lex_make_all: 216 | compiler_lex_clean: 217 | compiler_clean: 218 | 219 | ####### Compile 220 | 221 | bin/main.o: main.cpp SslHandler.h \ 222 | ClientSocketHandler.h \ 223 | HashDigestListener.h 224 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/main.o main.cpp 225 | 226 | bin/ClientSocketHandler.o: ClientSocketHandler.cpp ClientSocketHandler.h 227 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/ClientSocketHandler.o ClientSocketHandler.cpp 228 | 229 | bin/SslHandler.o: SslHandler.cpp SslHandler.h \ 230 | utils/fileutils.h 231 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/SslHandler.o SslHandler.cpp 232 | 233 | bin/fileutils.o: utils/fileutils.cpp utils/fileutils.h 234 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/fileutils.o utils/fileutils.cpp 235 | 236 | bin/stringutil.o: utils/stringutil.cpp utils/stringutil.h 237 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/stringutil.o utils/stringutil.cpp 238 | 239 | bin/HashDigestListener.o: HashDigestListener.cpp HashDigestListener.h 240 | $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bin/HashDigestListener.o HashDigestListener.cpp 241 | 242 | ####### Install 243 | 244 | install: FORCE 245 | 246 | uninstall: FORCE 247 | 248 | FORCE: 249 | 250 | -------------------------------------------------------------------------------- /digest-auth-session-test/SslHandler.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | SslHandler.cpp 26 | Manage ssl file formatted to QT ssl format cert 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #include "SslHandler.h" 32 | #include "utils/fileutils.h" 33 | #include "iostream" 34 | 35 | using namespace std; 36 | 37 | /** 38 | * @brief retrieveveCertFromFile 39 | * retrieve ssl certificate type file 40 | * @param filename 41 | * certificate file name (should be in pem format) 42 | * @return 43 | * QSslcertificate format 44 | */ 45 | QSslCertificate SslHandler::retrieveCertFromFile(char * filename){ 46 | 47 | //extract all cert in cert folder into byte array format 48 | QByteArray certFormatted= fileutils::readFromFile(filename); 49 | 50 | if (strcmp(certFormatted.data(),"")==0) 51 | { 52 | cout << "Invalid server certs ..." << endl; 53 | QSslCertificate cert; 54 | return cert; 55 | } 56 | 57 | //put all these cert into SSL QT object format 58 | QSslCertificate cert(certFormatted,QSsl::Pem); 59 | 60 | return cert; 61 | } 62 | 63 | QSslKey SslHandler::retrieveKeyCertFile(char * filename,char * certPass) 64 | { 65 | //extract all cert in cert folder into byte array format 66 | QByteArray certFormatted= fileutils::readFromFile(filename); 67 | 68 | if (strcmp(certFormatted.data(),"")==0) 69 | { 70 | cout << "Invalid server certs ..." << endl; 71 | QSslKey cert; 72 | return cert; 73 | } 74 | 75 | //put all these cert into SSL QT object format 76 | QSslKey keyObj(certFormatted, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, certPass); 77 | 78 | return keyObj; 79 | } 80 | 81 | /** 82 | * @brief retrieveveCaCertListFromFile 83 | * retrieve list of certification authorityto be used in server 84 | * @param filename 85 | * certificates file name (should be in pem format) 86 | * @return 87 | * QList< QSslCertificate > format 88 | */ 89 | QList< QSslCertificate > SslHandler::retrieveveCaCertListFromFile(char * filename){ 90 | 91 | QList< QSslCertificate > caCertificate; 92 | 93 | QByteArray caCert= fileutils::readFromFile(filename); 94 | 95 | if (strcmp(caCert.data(),"")==0) 96 | { 97 | cout << "Invalid server certs ..." << endl; 98 | return caCertificate; 99 | } 100 | 101 | //put all these cert into SSL QT object format 102 | QSslCertificate caCertObj(caCert,QSsl::Pem); 103 | 104 | caCertificate.push_back(caCertObj); 105 | 106 | return caCertificate; 107 | } 108 | -------------------------------------------------------------------------------- /digest-auth-session-test/SslHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | SslHandler.h 26 | Manage ssl file formatted to QT ssl format cert 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef SSLHANDLER_H 32 | #define SSLHANDLER_H 33 | #include "QSslCertificate" 34 | #include "QList" 35 | #include "QSslKey" 36 | 37 | /** 38 | * @brief The SslHandler class 39 | * format ssl file cert to QT format 40 | */ 41 | class SslHandler 42 | { 43 | public: 44 | 45 | /** 46 | * @brief retrieveveCertFromFile 47 | * retrieve ssl certificate type file 48 | * @param filename 49 | * certificate file name (should be in pem format) 50 | * @return 51 | * QSslcertificate format 52 | */ 53 | static QSslCertificate retrieveCertFromFile(char * filename); 54 | 55 | 56 | static QSslKey retrieveKeyCertFile(char * filename,char * certPass); 57 | 58 | 59 | /** 60 | * @brief retrieveveCaCertListFromFile 61 | * retrieve list of certification authorityto be used in server 62 | * @param filename 63 | * certificates file name (should be in pem format) 64 | * @return 65 | * QList< QSslCertificate > format 66 | */ 67 | static QList< QSslCertificate > retrieveveCaCertListFromFile(char * filename); 68 | }; 69 | 70 | #endif // SSLHANDLER_H 71 | -------------------------------------------------------------------------------- /digest-auth-session-test/digest-auth-session-test.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2015-09-03T00:13:52 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core 8 | QT += network 9 | 10 | QT -= gui 11 | 12 | TARGET = digest-auth-session-test 13 | CONFIG += console 14 | CONFIG -= app_bundle 15 | DESTDIR = release 16 | TEMPLATE = app 17 | OBJECTS_DIR=bin 18 | 19 | SOURCES += main.cpp \ 20 | ClientSocketHandler.cpp \ 21 | SslHandler.cpp \ 22 | utils/fileutils.cpp \ 23 | utils/stringutil.cpp \ 24 | HashDigestListener.cpp 25 | 26 | HEADERS += \ 27 | SslHandler.h \ 28 | ClientSocketHandler.h \ 29 | utils/fileutils.h \ 30 | utils/stringutil.h \ 31 | HashDigestListener.h 32 | 33 | 34 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../digest-auth-session-lib/libs/ -lhttpServer 35 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../digest-auth-session-lib/libs/ -lhttpServer 36 | else:unix: LIBS += -L$$PWD/../digest-auth-session-lib/libs/ -lhttpServer 37 | 38 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../digest-auth-session-lib/libs/ -lhttpdecoder 39 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../digest-auth-session-lib/libs/ -lhttpdecoder 40 | else:unix: LIBS += -L$$PWD/../digest-auth-session-lib/libs/ -lhttpdecoder 41 | 42 | win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../digest-auth-session-lib/release/ -ldigestauthsession 43 | else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../digest-auth-session-lib/release/ -ldigestauthsession 44 | else:unix: LIBS += -L$$PWD/../digest-auth-session-lib/release/ -ldigestauthsession 45 | 46 | INCLUDEPATH += $$PWD/libs 47 | INCLUDEPATH += $$PWD/../digest-auth-session-lib/libs 48 | INCLUDEPATH += $$PWD/../digest-auth-session-lib 49 | DEPENDPATH += $$PWD/libs 50 | 51 | QMAKE_CLEAN += -r $${PWD}/$${DESTDIR} 52 | 53 | QMAKE_POST_LINK +=$$quote(rsync -avm --include=*/ --include=*.h --exclude=* $${PWD}/$${SOURCES_DIR}/ $${PWD}/$${DESTDIR}) 54 | -------------------------------------------------------------------------------- /digest-auth-session-test/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | main.cpp 26 | 27 | Main test programm 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "string" 37 | #include 38 | #include "SslHandler.h" 39 | #include "httpserverimpl/httpserver.h" 40 | #include "ClientSocketHandler.h" 41 | #include "HashDigestListener.h" 42 | #include "DigestManager.h" 43 | 44 | using namespace std; 45 | 46 | static int port = 4343; 47 | static string ip="127.0.0.1"; 48 | static bool useSSL = false; 49 | 50 | #define ROOT_FOLDER "~" 51 | #define PUBLIC_CERT ROOT_FOLDER "/digest-auth-session-cpp/certs/server/server.crt" 52 | #define PRIVATE_CERT ROOT_FOLDER "/digest-auth-session-cpp/certs/server/server.key" 53 | #define CA_CERTS ROOT_FOLDER "/digest-auth-session-cpp/certs/ca.crt" 54 | #define PRIVATE_CERT_PASS "12345" 55 | 56 | struct CleanExit{ 57 | 58 | CleanExit() { 59 | 60 | signal(SIGINT, &CleanExit::exitQt); 61 | signal(SIGTERM, &CleanExit::exitQt); 62 | 63 | } 64 | 65 | static void exitQt(int sig) { 66 | 67 | QCoreApplication::exit(0); 68 | 69 | } 70 | }; 71 | 72 | int main(int argc, char *argv[]){ 73 | 74 | CleanExit cleanExit; 75 | QCoreApplication a(argc, argv); 76 | 77 | 78 | //ignore SIGPIPE signal (broken pipe issue) 79 | signal(SIGPIPE, SIG_IGN); 80 | 81 | QStringList args = a.arguments(); 82 | 83 | string ip ="127.0.0.1"; 84 | 85 | if (args.size() >2){ 86 | 87 | ip=args[1].toStdString(); 88 | bool ok = false; 89 | int dec = args[2].toInt(&ok, 10); 90 | 91 | if (ok) 92 | port = dec; 93 | } 94 | 95 | HashDigestListener digest_listener; 96 | DigestManager digest_manager; 97 | digest_manager.set_digest_algorithm(ALGO_SHA1); 98 | digest_manager.set_session_type(SESSION_DIGEST); 99 | 100 | digest_manager.set_digest_listener(&digest_listener); 101 | 102 | ClientSocketHandler clientHandler(&digest_manager); 103 | 104 | //instance of HTTP server 105 | HttpServer server; 106 | server.set_debug(false); 107 | 108 | if (useSSL){ 109 | //set secured HTTP server 110 | server.setSSL(true); 111 | 112 | cout << "setting server certs ..." << endl; 113 | 114 | //set public / private and certification authority list into http server object 115 | server.setPublicCert(SslHandler::retrieveCertFromFile(PUBLIC_CERT)); 116 | server.setPrivateCert(SslHandler::retrieveKeyCertFile(PRIVATE_CERT,PRIVATE_CERT_PASS)); 117 | server.setCaCert(SslHandler::retrieveveCaCertListFromFile(CA_CERTS)); 118 | } 119 | 120 | server.addClientEventListener(&clientHandler); 121 | 122 | if (!server.listen(QHostAddress(ip.data()),port)) { 123 | qDebug() << "An error occured while initializing hope proxy server... Maybe another instance is already running on "<< ip.data() << ":" << port << endl; 124 | return -1; 125 | } 126 | 127 | cout << "Starting HTTP server on "<< ip.data() << port << endl; 128 | 129 | return a.exec(); 130 | } 131 | -------------------------------------------------------------------------------- /digest-auth-session-test/release/ClientSocketHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | ClientSocketHandler.h 26 | Client socket managing event handler 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef CLIENTSOCKETHANDLER_H 32 | #define CLIENTSOCKETHANDLER_H 33 | 34 | #include "httpserverinter/IClientEventListener.h" 35 | #include "DigestManager.h" 36 | 37 | /** 38 | * @brief The ClientSocketHandler class 39 | * Client socket managing event handler 40 | */ 41 | class ClientSocketHandler : public IClientEventListener 42 | { 43 | public: 44 | 45 | /** 46 | * @brief ClientSocketHandler 47 | * build client socket handler 48 | */ 49 | ClientSocketHandler(DigestManager * digest_manager); 50 | 51 | ~ClientSocketHandler(); 52 | 53 | /** 54 | * called when an http request has been received from client 55 | * 56 | * @param client 57 | * client object 58 | * @param message 59 | * message delivered 60 | */ 61 | void onHttpRequestReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address); 62 | 63 | /** 64 | * called when an http response has been received from client 65 | * 66 | * @param client 67 | * client object 68 | * @param message 69 | * message delivered 70 | */ 71 | void onHttpResponseReceived(IHttpClient &client,Ihttpframe* consumer,std::string peer_address); 72 | 73 | private: 74 | DigestManager * digest_manager; 75 | 76 | std::string unauthorized_page; 77 | 78 | std::string internal_error_page; 79 | 80 | std::string login_success_page; 81 | }; 82 | 83 | #endif // CLIENTSOCKETHANDLER_H 84 | -------------------------------------------------------------------------------- /digest-auth-session-test/release/HashDigestListener.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | HashDigestListener.h 26 | 27 | Listener for retrieving username / password hash from storage 28 | 29 | @author Bertrand Martel 30 | @version 1.0 31 | */ 32 | #ifndef HASHDIGESTLISTENER_H 33 | #define HASHDIGESTLISTENER_H 34 | 35 | #include "string" 36 | #include "IDigestListener.h" 37 | #include "digeststruct.h" 38 | 39 | class HashDigestListener : public IDigestListener { 40 | 41 | public: 42 | 43 | /** 44 | * @brief ClientSocketObj::ClientSocketObj 45 | * Build one client 46 | */ 47 | HashDigestListener(); 48 | 49 | ~HashDigestListener(); 50 | 51 | /** 52 | * @brief get_hash_for_username 53 | * retrieve hash in database or in your configuration for specified username and realm 54 | * @return 55 | */ 56 | std::string get_hash_for_username(std::string username,std::string realm,digest_algorithm algo); 57 | 58 | }; 59 | 60 | #endif // HASHDIGESTLISTENER_H 61 | -------------------------------------------------------------------------------- /digest-auth-session-test/release/SslHandler.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Bertrand Martel 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | /** 25 | SslHandler.h 26 | Manage ssl file formatted to QT ssl format cert 27 | 28 | @author Bertrand Martel 29 | @version 1.0 30 | */ 31 | #ifndef SSLHANDLER_H 32 | #define SSLHANDLER_H 33 | #include "QSslCertificate" 34 | #include "QList" 35 | #include "QSslKey" 36 | 37 | /** 38 | * @brief The SslHandler class 39 | * format ssl file cert to QT format 40 | */ 41 | class SslHandler 42 | { 43 | public: 44 | 45 | /** 46 | * @brief retrieveveCertFromFile 47 | * retrieve ssl certificate type file 48 | * @param filename 49 | * certificate file name (should be in pem format) 50 | * @return 51 | * QSslcertificate format 52 | */ 53 | static QSslCertificate retrieveCertFromFile(char * filename); 54 | 55 | 56 | static QSslKey retrieveKeyCertFile(char * filename,char * certPass); 57 | 58 | 59 | /** 60 | * @brief retrieveveCaCertListFromFile 61 | * retrieve list of certification authorityto be used in server 62 | * @param filename 63 | * certificates file name (should be in pem format) 64 | * @return 65 | * QList< QSslCertificate > format 66 | */ 67 | static QList< QSslCertificate > retrieveveCaCertListFromFile(char * filename); 68 | }; 69 | 70 | #endif // SSLHANDLER_H 71 | -------------------------------------------------------------------------------- /digest-auth-session-test/release/digest-auth-session-test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bertrandmartel/digest-auth-session-cpp/HEAD/digest-auth-session-test/release/digest-auth-session-test -------------------------------------------------------------------------------- /digest-auth-session-test/release/utils/fileutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | fileutils.h 3 | Functions used to manage files 4 | 5 | @author Bertrand Martel 6 | @version 1.0 7 | */ 8 | #ifndef FILEUTILS_H 9 | #define FILEUTILS_H 10 | 11 | #include "QByteArray" 12 | 13 | class fileutils 14 | { 15 | public: 16 | 17 | /** 18 | * @brief fileutils::readFromFile 19 | * read file data content and extract it into QByteArray 20 | * @param fileName 21 | * file to extract 22 | * @return 23 | */ 24 | static QByteArray readFromFile(char * fileName); 25 | 26 | 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /digest-auth-session-test/release/utils/stringutil.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGUTIL_H 2 | #define STRINGUTIL_H 3 | 4 | #include "string" 5 | #include 6 | 7 | class stringutil 8 | { 9 | public: 10 | 11 | static std::string replaceAll(std::string str, const std::string& from, const std::string& to); 12 | 13 | static std::vector split(const std::string &s, char delim, std::vector &elems); 14 | 15 | static std::vector split(const std::string &s, char delim); 16 | }; 17 | 18 | #endif // STRINGUTIL_H 19 | -------------------------------------------------------------------------------- /digest-auth-session-test/utils/fileutils.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | fileutils.cpp 3 | Functions used to manage files 4 | 5 | @author Bertrand Martel 6 | @version 1.0 7 | */ 8 | #include "fileutils.h" 9 | #include "QFile" 10 | #include "iostream" 11 | 12 | using namespace std; 13 | 14 | /** 15 | * @brief fileutils::readFromFile 16 | * read file data content and extract it into QByteArray 17 | * @param fileName 18 | * file to extract 19 | * @return 20 | */ 21 | QByteArray fileutils::readFromFile(char * fileName) 22 | { 23 | QFile file(fileName); 24 | 25 | QByteArray byteArray; 26 | 27 | if(file.open(QIODevice::ReadOnly)) 28 | { 29 | byteArray = file.readAll(); 30 | file.close(); 31 | } 32 | else 33 | { 34 | cout << file.errorString().toStdString().data() << endl; 35 | } 36 | 37 | return byteArray; 38 | } 39 | -------------------------------------------------------------------------------- /digest-auth-session-test/utils/fileutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | fileutils.h 3 | Functions used to manage files 4 | 5 | @author Bertrand Martel 6 | @version 1.0 7 | */ 8 | #ifndef FILEUTILS_H 9 | #define FILEUTILS_H 10 | 11 | #include "QByteArray" 12 | 13 | class fileutils 14 | { 15 | public: 16 | 17 | /** 18 | * @brief fileutils::readFromFile 19 | * read file data content and extract it into QByteArray 20 | * @param fileName 21 | * file to extract 22 | * @return 23 | */ 24 | static QByteArray readFromFile(char * fileName); 25 | 26 | 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /digest-auth-session-test/utils/stringutil.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | stringutil.cpp 3 | 4 | String functions 5 | 6 | @author Bertrand Martel 7 | @version 1.0 8 | */ 9 | #include "stringutil.h" 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | std::string stringutil::replaceAll(std::string str, const std::string& from, const std::string& to) { 16 | size_t start_pos = 0; 17 | while((start_pos = str.find(from, start_pos)) != std::string::npos) { 18 | str.replace(start_pos, from.length(), to); 19 | start_pos += to.length(); // Handles case where 'to' is a substring of 'from' 20 | } 21 | return str; 22 | } 23 | 24 | std::vector stringutil::split(const std::string &s, char delim, std::vector &elems) { 25 | stringstream ss(s); 26 | string item; 27 | while (getline(ss, item, delim)) { 28 | elems.push_back(item); 29 | } 30 | return elems; 31 | } 32 | 33 | std::vector stringutil::split(const std::string &s, char delim) { 34 | vector elems; 35 | split(s, delim, elems); 36 | return elems; 37 | } 38 | -------------------------------------------------------------------------------- /digest-auth-session-test/utils/stringutil.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGUTIL_H 2 | #define STRINGUTIL_H 3 | 4 | #include "string" 5 | #include 6 | 7 | class stringutil 8 | { 9 | public: 10 | 11 | static std::string replaceAll(std::string str, const std::string& from, const std::string& to); 12 | 13 | static std::vector split(const std::string &s, char delim, std::vector &elems); 14 | 15 | static std::vector split(const std::string &s, char delim); 16 | }; 17 | 18 | #endif // STRINGUTIL_H 19 | -------------------------------------------------------------------------------- /memcheck.suppress: -------------------------------------------------------------------------------- 1 | { 2 | 3 | Memcheck:Leak 4 | match-leak-kinds: definite 5 | fun:_Znwj 6 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 7 | fun:_ZN8QLibrary21setFileNameAndVersionERK7QStringS2_ 8 | fun:_ZN8QLibraryC1ERK7QStringS2_P7QObject 9 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 10 | fun:_ZN14QLocalePrivate19updateSystemPrivateEv 11 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 12 | fun:_ZN7QLocaleC1Ev 13 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 14 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 15 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 16 | fun:_ZN9QFileInfoC1ERK7QString 17 | } 18 | { 19 | 20 | Memcheck:Leak 21 | match-leak-kinds: definite 22 | fun:_Znwj 23 | obj:/usr/lib/i386-linux-gnu/libQtCore.so.4.8.4 24 | fun:_ZN8QLibrary21setFileNameAndVersionERK7QStringS2_ 25 | obj:/usr/lib/i386-linux-gnu/libQtNetwork.so.4.8.4 26 | obj:/usr/lib/i386-linux-gnu/libQtNetwork.so.4.8.4 27 | obj:/usr/lib/i386-linux-gnu/libQtNetwork.so.4.8.4 28 | fun:_ZN15QSslCertificateC1ERK10QByteArrayN4QSsl14EncodingFormatE 29 | fun:_ZN10HttpServerC1EP7QObject 30 | } 31 | -------------------------------------------------------------------------------- /test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bertrandmartel/digest-auth-session-cpp/HEAD/test.png --------------------------------------------------------------------------------