-2

我正在编写一段 C++ 代码,它将保存加密存档的访问密钥,并且不允许在 Linux 系统上的某个日期之前查看它。

完整的代码如下(是的,它很丑陋并且有一个system()电话。我觉得这对于给定的情况是必要的):

#include <iostream> //cout
#include <ctime> //time_t, time()
#include <cstdlib> //system()
#include <unistd.h> //getuid()
using namespace std;

int main () { 
        //updates the system clock and catches the exit code; must be 0 to proceed
        int tcheck = system ("ntpd -q -I pool.ntp.org");
        //checks updated time against set timestamp (11/20/16 @ 12 PM) and gives or denies access to key respectively
        if ((tcheck  == 0) && (getuid() = 0)) {
                time_t now = time(0);
                if (now < 1479661235)
                {cout << "It is not yet time.";}
                else
                {cout << "The key is: a placeholder";}
        }
        else if (getuid() != 0)
        {cout << "This program must be run as root.";}
        else if (tcheck != 0)
        {cout << "I think you might be cheating. Let the time server sync and then we'll talk.";}
        cin.get();
        return 0;
}

我的问题如下。具有特权的用户必须无法访问该密钥sudo(只有手中的可执行文件),但是对于这样的用户来说,简单地删除/bin/ntpd并用一个在调用时返回 0 的虚拟程序替换它会相对容易,从而避免了时间篡改保护。

我考虑使用校验和来确保程序的有效性,但基于临时更新 ntp 包也可能更改 ntpd 并使密钥无法访问这一事实而放弃了这一点。我也不能从包管理器中调用 ntpd 的校验和,因为代码必须可以跨多个发行版移植。

对于如何确保程序的有效性(或完全不同的方法来实现相同的结果),你们有什么想法吗?

PS:在你提到它之前,我确实计划混淆源代码以避免反编译器利用,所以这不会成为问题。

4

1 回答 1

0

鉴于网络必须始终可用才能使用该程序,请将所有安全性转移到服务器。在客户端,您将拥有类似的东西

wget https://www.yourserver.com/getkey?keyid=xxxxxxxxxxxxxxxxxxxxx

其中参数 tokeyid是所需密钥的某个标识符(可能是它的 SHA1 加了一些秘密,但无论如何);仅当时间到时,您的服务器才会提供所需的密钥。

于 2016-08-13T17:26:33.363 回答