Revision: 10694 https://osdn.net/projects/ttssh2/scm/svn/commits/10694 Author: zmatsuo Date: 2023-05-02 22:27:42 +0900 (Tue, 02 May 2023) Log Message: ----------- ttssh2/libsshagentc/skelton を追加 - ssh agent と通信部の骨格 - debug/テスト用 - sshagentc_tool/ 追加 - debug/テスト用 Modified Paths: -------------- trunk/ttssh2/libsshagentc/CMakeLists.txt trunk/ttssh2/libsshagentc/README.md Added Paths: ----------- trunk/ttssh2/libsshagentc/skelton/ trunk/ttssh2/libsshagentc/skelton/CMakeLists.txt trunk/ttssh2/libsshagentc/skelton/skelton.c trunk/ttssh2/libsshagentc/sshagentc_tool/ trunk/ttssh2/libsshagentc/sshagentc_tool/CMakeLists.txt trunk/ttssh2/libsshagentc/sshagentc_tool/main.cpp -------------- next part -------------- Modified: trunk/ttssh2/libsshagentc/CMakeLists.txt =================================================================== --- trunk/ttssh2/libsshagentc/CMakeLists.txt 2023-05-02 13:27:32 UTC (rev 10693) +++ trunk/ttssh2/libsshagentc/CMakeLists.txt 2023-05-02 13:27:42 UTC (rev 10694) @@ -1,4 +1,13 @@ cmake_minimum_required(VERSION 3.11) project(libsshagentc) -add_subdirectory(putty) +option(SSHAGENTC_SKELTON "use skelton" OFF) + +if(SSHAGENTC_SKELTON) + add_subdirectory(skelton) +else() + add_subdirectory(putty) +endif() + +# for debug/test +#add_subdirectory(sshagentc_tool) Modified: trunk/ttssh2/libsshagentc/README.md =================================================================== --- trunk/ttssh2/libsshagentc/README.md 2023-05-02 13:27:32 UTC (rev 10693) +++ trunk/ttssh2/libsshagentc/README.md 2023-05-02 13:27:42 UTC (rev 10694) @@ -8,6 +8,9 @@ - libsshagentc インターフェイス - putty/ - putty 0.76 を利用した ssh-agent client +- skelton/ + - クライアントスケルトン + - 何も行わない # 資料 Added: trunk/ttssh2/libsshagentc/skelton/CMakeLists.txt =================================================================== --- trunk/ttssh2/libsshagentc/skelton/CMakeLists.txt (rev 0) +++ trunk/ttssh2/libsshagentc/skelton/CMakeLists.txt 2023-05-02 13:27:42 UTC (rev 10694) @@ -0,0 +1,15 @@ +set(PACKAGE_NAME "libsshagentc") + +project(${PACKAGE_NAME}) + +add_library( + ${PACKAGE_NAME} + ../libputty.h + skelton.c +) + +target_include_directories( + ${PACKAGE_NAME} + PRIVATE + .. +) Added: trunk/ttssh2/libsshagentc/skelton/skelton.c =================================================================== --- trunk/ttssh2/libsshagentc/skelton/skelton.c (rev 0) +++ trunk/ttssh2/libsshagentc/skelton/skelton.c 2023-05-02 13:27:42 UTC (rev 10694) @@ -0,0 +1,56 @@ + +#include <stdlib.h> +#include "libputty.h" + +int putty_get_ssh2_keylist(unsigned char **keylist) +{ + *keylist = NULL; + return 0; +} + +void *putty_sign_ssh2_key(unsigned char *pubkey, + unsigned char *data, + int datalen, + int *outlen, + int signflags) +{ + return NULL; +} + +int putty_get_ssh1_keylist(unsigned char **keylist) +{ + return 0; +} + +void *putty_hash_ssh1_challenge(unsigned char *pubkey, + int pubkeylen, + unsigned char *data, + int datalen, + unsigned char *session_id, + int *outlen) +{ + return NULL; +} + +int putty_get_ssh1_keylen(unsigned char *key, int maxlen) +{ + return 0; +} + +const char *putty_get_version() +{ + return "libsshagent 0.0"; +} + +void putty_agent_query_synchronous(void *in, int inlen, void **out, int *outlen) +{} + +BOOL putty_agent_exists() +{ + return FALSE; +} + +void safefree(void *p) +{ + free(p); +} Added: trunk/ttssh2/libsshagentc/sshagentc_tool/CMakeLists.txt =================================================================== --- trunk/ttssh2/libsshagentc/sshagentc_tool/CMakeLists.txt (rev 0) +++ trunk/ttssh2/libsshagentc/sshagentc_tool/CMakeLists.txt 2023-05-02 13:27:42 UTC (rev 10694) @@ -0,0 +1,32 @@ +set(PACKAGE_NAME "sshagentc_tool") + +project(${PACKAGE_NAME}) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/") + +add_executable( + ${PACKAGE_NAME} + main.cpp + ../libputty.h +) + +target_include_directories( + ${PACKAGE_NAME} + PRIVATE + . + ../ +) + +target_link_libraries( + ${PACKAGE_NAME} + PRIVATE + libsshagentc +) + +if(MINGW) + target_link_options( + ${PACKAGE_NAME} + PRIVATE + -municode + ) +endif() Added: trunk/ttssh2/libsshagentc/sshagentc_tool/main.cpp =================================================================== --- trunk/ttssh2/libsshagentc/sshagentc_tool/main.cpp (rev 0) +++ trunk/ttssh2/libsshagentc/sshagentc_tool/main.cpp 2023-05-02 13:27:42 UTC (rev 10694) @@ -0,0 +1,120 @@ +/* + * (C) 2022- TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <locale.h> +#include <windows.h> +#define _CRTDBG_MAP_ALLOC +#include <crtdbg.h> +#include <stdint.h> +#include <vector> + +#include "libputty.h" +//#include "sshagent/sha256.h" + +void put_byte(std::vector<uint8_t> &buf, uint8_t b) +{ + buf.push_back(b); +} + +void put_data(std::vector<uint8_t> &buf, const void *ptr, size_t len) +{ + const uint8_t *u8ptr = (uint8_t *)ptr; + buf.insert(buf.end(), &u8ptr[0], &u8ptr[len]); +} + +void put_uint32(std::vector<uint8_t> &buf, uint32_t u32) +{ + buf.push_back((u32 >> (8*3)) & 0xff); + buf.push_back((u32 >> (8*2)) & 0xff); + buf.push_back((u32 >> (8*1)) & 0xff); + buf.push_back((u32 >> (8*0)) & 0xff); +} + +/* + * OpenSSH's SSH-2 agent messages. + */ +#define SSH2_AGENTC_REQUEST_IDENTITIES 11 +#define SSH2_AGENT_IDENTITIES_ANSWER 12 +#define SSH2_AGENTC_SIGN_REQUEST 13 +#define SSH2_AGENT_SIGN_RESPONSE 14 +#define SSH2_AGENTC_ADD_IDENTITY 17 +#define SSH2_AGENTC_REMOVE_IDENTITY 18 +#define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19 +#define SSH2_AGENTC_EXTENSION 27 +#define SSH_AGENT_EXTENSION_FAILURE 28 + +static void query() +{ + std::vector<uint8_t> buf; + put_uint32(buf, 1); + put_byte(buf, SSH2_AGENTC_REQUEST_IDENTITIES); + + uint8_t *out_ptr; + int out_len; + putty_agent_query_synchronous(&buf[0], (int)buf.size(), (void **)&out_ptr, &out_len); + + // SSH_AGENT_IDENTITIES_ANSWER(12, 0x0c) \x82\xAA\x95Ԃ\xC1\x82Ă\xAD\x82\xE9 + safefree(out_ptr); +} + +void ssh2_key() +{ + unsigned char *keylist; + int r = putty_get_ssh2_keylist(&keylist); + safefree(keylist); +} + +int wmain(int argc, wchar_t *argv[]) +{ + setlocale(LC_ALL, ""); + +#ifdef _DEBUG + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif +#if 0 + if (0) { + const char s[] = "hoge"; + size_t l = sizeof(s) - 1; + uint8_t digest[32]; + sha256(s, l, digest); + } +#endif + if (0) { + query(); + } + if (1) { + putty_agent_exists(); + } + if (1) { + ssh2_key(); + } + + _CrtCheckMemory(); + return 0; +}