title: Profile Installation Failed: The SCEP server returned an invalid response (occurring when profile is modified)
body: <p>I'm trying to experiment with configuration profiles and in order to do that I am starting out with one created by Apple's Profile Manager application that uses SCEP. When I take the .mobileconfig file and install in on the device (using Apple Configurator 2) it installs fine without any issue.</p>
  
  <p>However, I noticed that if I modify anything in this profile (even something minor like "PayloadDisplayName") the enrollment process gets to the end but ends up failing with this error:</p>
  
  <pre><code>Profile Installation Failed: 
  The SCEP server returned an invalid response 
  </code></pre>
  
  <p>Looking at console logging doesn't show much of use:</p>
  
  <pre><code>default 14:00:17.421822-0700    profiled    Could not retrieve issued certificate: NSError:
  Desc   : The SCEP server returned an invalid response.
  US Desc: The SCEP server returned an invalid response.
  Domain : MCSCEPErrorDomain
  Code   : 22013
  Type   : MCFatalError
  error   14:00:17.422199-0700    profiled    Cannot retrieve SCEP identity: NSError:
  Desc   : The SCEP server returned an invalid response.
  US Desc: The SCEP server returned an invalid response.
  Domain : MCSCEPErrorDomain
  Code   : 22013
  Type   : MCFatalError
  error   14:00:17.422306-0700    profiled    Rolling back installation of profile 
  </code></pre>
  
  <p>It seems there is some sort of signing or checksum being used, but this is strange since the profile specifically says it is not signed. Looking at all the fields in use, the only thing I can guess is that the challenge field is somehow involved. Apple's documentation gives a hint about this field here:</p>
  
  <blockquote>
    <p>The front end service can be set up to gate access by means of a
    challenge, which in practice is an authorization token (a one-time
    password, or <strong>a signed/encrypted blob containing user/device info</strong>) to
    allow automatic issuing of a certificate.</p>
  </blockquote>
  
  <p>However the above is only a recommendation, and I am not able to find out how the challenge parameter is actually defined (the value I am using is <em>oBGLAsWsMWnHiycHpBaHXNmVEDevrLt</em>). I'm using the SCEP server that comes with Profile Manager but I have been unable to find any documentation about this, and the logging that is supposed to be present in the console log (with key "com.apple.SCEP") doesn't seem to exist.</p>
  
  <p>If I remove the challenge parameter completely from the profile, I get a prompt during device enrollment, but I'm not sure what I should be putting in there.</p>
  
  <p>If anyone has any ideas, please let me know.</p>
  
  <p><strong>UDPATE: Looking in /Library/Logs/ProfileManager/dmSCEPService.log I see these errors:</strong></p>
  
  <pre><code>0:: [335] [2019/06/19 14:00:16.917] Certificate placeholder with challengePassword not found
  0:: [335] [2019/06/19 14:00:16.917] EXCEPTION: SCEP BAD CHALLENGE &lt;SCEP BAD CHALLENGE&gt;
      USERINFO: {
          NSLocalizedDescription = "Unknown error 20";
      }
  </code></pre>
  
  <p>This confirms it is the challenge causing the issue, but I'm not sure how to generate a proper challenge so things will succeed.</p>